net.logAnalyzer.utils
Class FilesSetReader

java.lang.Object
  extended bynet.logAnalyzer.utils.FilesSetReader
All Implemented Interfaces:
java.io.DataInput

public final class FilesSetReader
extends java.lang.Object
implements java.io.DataInput

This class is a wrapper is used to read a set of files. This implementation acts as a wrapper supporting a small number of methods of the class RandomAccessFile.

Version:
0.1
Author:
Karim REFEYTON

Constructor Summary
FilesSetReader()
          Default construtor.
 
Method Summary
 void close()
          Closes this random access file stream and releases any system resources associated with the stream.
 long getFilePointer()
          Returns the current offset in this log file.
 long length()
          Returns the total length of files in the set.
 int read()
          Reads a byte of data from this file using RandomAccessFile.read() on the current file of the set of files.
 boolean readBoolean()
          Reads one input byte using read() and returns true if that byte is nonzero, false if that byte is zero.
 byte readByte()
          Reads one input byte using read() and casts it to byte.
 char readChar()
          Reads an unsigned short using readUnsignedShort() and casts it to char.
 double readDouble()
          Reads a double from this file.
 float readFloat()
          Reads a float from this file.
 void readFully(byte[] b)
          Reads b.length bytes from this file into the byte array using readFully(byte[], int, int), starting at the current file pointer.
 void readFully(byte[] b, int off, int len)
          Reads exactly len bytes from this file into the byte array unsing readByte(), starting at the current file pointer.
 int readInt()
          Reads four input bytes using read() and combines them to int.
 java.lang.String readLine()
          Reads the next line of text from this file.
 long readLong()
          Reads eight input bytes using read() twice and combines them to long.
 short readShort()
          Reads an unsigned short using readUnsignedShort() and casts it to short.
 int readUnsignedByte()
          Reads a single input byte using read() and returns it.
 int readUnsignedShort()
          Reads two input bytes using read() and combines them to int as an unsigned short.
 java.lang.String readUTF()
          Reads in a string that has been encoded using a modified UTF-8 format.
 void seek(long pos)
          Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
 void setFiles(java.io.File[] inputFiles)
          Opens each input file as a new RandomAccessFile with mode "r".
 int skipBytes(int n)
          Attempts to skip over n bytes of input discarding the skipped bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilesSetReader

public FilesSetReader()
Default construtor. Constructs an empty file set.

Method Detail

getFilePointer

public long getFilePointer()
                    throws java.io.IOException
Returns the current offset in this log file.

Returns:
The offset from the beginning of the file, in bytes, at which the next read or write occurs.
Throws:
java.io.IOException - If an I/O error occurs.
See Also:
RandomAccessFile.getFilePointer()

setFiles

public void setFiles(java.io.File[] inputFiles)
              throws java.io.FileNotFoundException
Opens each input file as a new RandomAccessFile with mode "r".

Parameters:
inputFiles - Files to read.
Throws:
java.io.FileNotFoundException - If one or more files exist but is a directory rather than regular files, or cannot be opened or created for any other reason.
See Also:
RandomAccessFile.RandomAccessFile(java.io.File, java.lang.String)

close

public void close()
           throws java.io.IOException
Closes this random access file stream and releases any system resources associated with the stream.

Throws:
java.io.IOException - If an I/O error occurs.
See Also:
java.io.Closeable#close()

length

public long length()
Returns the total length of files in the set.

Returns:
Total length of files in the set.

read

public int read()
         throws java.io.IOException
Reads a byte of data from this file using RandomAccessFile.read() on the current file of the set of files. If the end of current file is reached and the set contains more than one file, tries to read from the next file.

Returns:
the next byte of data, or -1 if the end of the file has been reached.
Throws:
java.io.IOException - if an I/O error occurs. Not thrown if end-of-file has been reached.
See Also:
RandomAccessFile.read()

readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Reads one input byte using read() and returns true if that byte is nonzero, false if that byte is zero.

Specified by:
readBoolean in interface java.io.DataInput
Returns:
the boolean value read.
Throws:
java.io.EOFException - if this file has reached the end.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readBoolean()

readByte

public byte readByte()
              throws java.io.IOException
Reads one input byte using read() and casts it to byte.

Specified by:
readByte in interface java.io.DataInput
Returns:
the byte value read.
Throws:
java.io.EOFException - if this file has reached the end.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readByte()

readChar

public char readChar()
              throws java.io.IOException
Reads an unsigned short using readUnsignedShort() and casts it to char.

Specified by:
readChar in interface java.io.DataInput
Returns:
the char value read.
Throws:
java.io.EOFException - if this file has reached the end.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readChar()

readDouble

public double readDouble()
                  throws java.io.IOException
Reads a double from this file. This method reads a long value, starting at the current file pointer, as if by the readLong method and then converts that long to a double using Double.longBitsToDouble(long).

Specified by:
readDouble in interface java.io.DataInput
Returns:
the double value read.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readDouble()

readFloat

public float readFloat()
                throws java.io.IOException
Reads a float from this file. This method reads a long value, starting at the current file pointer, as if by the readLong method and then converts that long to a float using Float.intBitsToFloat(int).

Specified by:
readFloat in interface java.io.DataInput
Returns:
the float value read.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readFloat()

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
Reads exactly len bytes from this file into the byte array unsing readByte(), starting at the current file pointer. This method reads repeatedly from the file until the requested number of bytes are read. This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown.

Specified by:
readFully in interface java.io.DataInput
Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the number of bytes to read.
Throws:
java.io.EOFException - if this file reaches the end before reading all the bytes.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readFully(byte[], int, int)

readFully

public void readFully(byte[] b)
               throws java.io.IOException
Reads b.length bytes from this file into the byte array using readFully(byte[], int, int), starting at the current file pointer.

Specified by:
readFully in interface java.io.DataInput
Parameters:
b - the buffer into which the data is read.
Throws:
java.io.EOFException - if this file reaches the end before reading all the bytes.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readFully(byte[])

readInt

public int readInt()
            throws java.io.IOException
Reads four input bytes using read() and combines them to int.

Specified by:
readInt in interface java.io.DataInput
Returns:
the int value read.
Throws:
java.io.EOFException - if this file has reached the end.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readInt()

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads the next line of text from this file. If the end of current file is reached and the set contains more than one file, tries to read from the next file.

Specified by:
readLine in interface java.io.DataInput
Returns:
The next line of text from this file, or null if end of file is encountered before even one byte is read.
Throws:
java.io.IOException - If an I/O error occurs.
See Also:
DataInput.readLine()

readLong

public long readLong()
              throws java.io.IOException
Reads eight input bytes using read() twice and combines them to long.

Specified by:
readLong in interface java.io.DataInput
Returns:
the long value read.
Throws:
java.io.EOFException - if this file has reached the end.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readLong()

readShort

public short readShort()
                throws java.io.IOException
Reads an unsigned short using readUnsignedShort() and casts it to short.

Specified by:
readShort in interface java.io.DataInput
Returns:
the short value read.
Throws:
java.io.EOFException - if this file has reached the end.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readShort()

readUnsignedByte

public int readUnsignedByte()
                     throws java.io.IOException
Reads a single input byte using read() and returns it.

Specified by:
readUnsignedByte in interface java.io.DataInput
Returns:
the int value read.
Throws:
java.io.EOFException - if this file has reached the end.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readUnsignedByte()

readUnsignedShort

public int readUnsignedShort()
                      throws java.io.IOException
Reads two input bytes using read() and combines them to int as an unsigned short.

Specified by:
readUnsignedShort in interface java.io.DataInput
Returns:
the int value read.
Throws:
java.io.EOFException - if this file has reached the end.
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.readUnsignedShort()

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Reads in a string that has been encoded using a modified UTF-8 format.

Specified by:
readUTF in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readUTF()

seek

public void seek(long pos)
          throws java.io.IOException
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.

Parameters:
pos - The offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
Throws:
java.io.IOException - If an I/O error occurs.
See Also:
RandomAccessFile.seek(long)

skipBytes

public int skipBytes(int n)
              throws java.io.IOException
Attempts to skip over n bytes of input discarding the skipped bytes.

Specified by:
skipBytes in interface java.io.DataInput
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
DataInput.skipBytes(int)


Copyright © 2006 null. All Rights Reserved.