org.foray.common.io
Class RandomAccessInputFile

java.lang.Object
  extended by org.foray.common.io.AbstractRandomAccessInput
      extended by org.foray.common.io.RandomAccessInputFile
All Implemented Interfaces:
DataInput, RandomAccessInput

public class RandomAccessInputFile
extends AbstractRandomAccessInput

Implementation of RandomInput that uses a RandomAccessFile to do the io work.


Constructor Summary
RandomAccessInputFile(File file)
          Constructor.
 
Method Summary
 String getDescription()
          Provides some kind of description of this item, useful in user messages.
 InputStream getInputStream()
          Return the input as an InputStream.
 long getOffset()
          Returns the current offset in this input.
 long length()
          Returns the length of this input.
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
 double readDouble()
           
 float readFloat()
           
 void readFully(byte[] b)
           
 void readFully(byte[] b, int off, int len)
           
 int readInt()
           
 String readLine()
           
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 String readUTF()
           
 void seek(long offset)
          Sets the input pointer offset, measured from the beginning of the input, at which the next read occurs.
 int skipBytes(int add)
           
 
Methods inherited from class org.foray.common.io.AbstractRandomAccessInput
createRandomAccessInput, createRandomAccessInput, createRandomAccessInput, readFixed16x16Signed, readNullTerminatedString, readShortLoHi, readString, readStringASCII, readTerminatedString, readUnsignedInt, readUnsignedIntLoHi, readUnsignedShortLoHi
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomAccessInputFile

public RandomAccessInputFile(File file)
                      throws IOException
Constructor.

Parameters:
file - The wrapped file to be read.
Throws:
IOException - For error opening or reading file.
Method Detail

seek

public void seek(long offset)
          throws IOException
Description copied from interface: RandomAccessInput

Sets the input pointer offset, measured from the beginning of the input, at which the next read occurs. The offset may be set beyond the end of the input. Setting the offset beyond the end of the input does not change the input length.

This method is based on RandomAccessFile.seek(long).

Parameters:
offset - The offset position, measured in bytes from the beginning of the input, at which to set the input pointer.
Throws:
IOException - If pos is less than 0, or if an I/O error occurs.
See Also:
RandomAccessFile.seek(long)

skipBytes

public int skipBytes(int add)
              throws IOException
Throws:
IOException

length

public long length()
            throws IOException
Description copied from interface: RandomAccessInput

Returns the length of this input.

This method is based on RandomAccessFile.length().

Returns:
The length of the input, measured in bytes.
Throws:
IOException - If an I/O error occurs.
See Also:
RandomAccessFile.length()

readByte

public byte readByte()
              throws IOException
Throws:
IOException

readUnsignedByte

public final int readUnsignedByte()
                           throws IOException
Throws:
IOException

readShort

public final short readShort()
                      throws IOException
Throws:
IOException

readUnsignedShort

public final int readUnsignedShort()
                            throws IOException
Throws:
IOException

readDouble

public final double readDouble()
                        throws IOException
Throws:
IOException

readBoolean

public final boolean readBoolean()
                          throws IOException
Throws:
IOException

readFully

public final void readFully(byte[] b)
                     throws IOException
Throws:
IOException

readFully

public final void readFully(byte[] b,
                            int off,
                            int len)
                     throws IOException
Throws:
IOException

readLong

public final long readLong()
                    throws IOException
Throws:
IOException

readFloat

public final float readFloat()
                      throws IOException
Throws:
IOException

readChar

public final char readChar()
                    throws IOException
Throws:
IOException

readUTF

public final String readUTF()
                     throws IOException
Throws:
IOException

readInt

public final int readInt()
                  throws IOException
Throws:
IOException

readLine

public final String readLine()
                      throws IOException
Throws:
IOException

getOffset

public long getOffset()
               throws IOException
Description copied from interface: RandomAccessInput

Returns the current offset in this input.

This method is based on RandomAccessFile.getFilePointer().

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

getDescription

public String getDescription()
Description copied from interface: RandomAccessInput
Provides some kind of description of this item, useful in user messages.

Returns:
A description of the contents of this item.

getInputStream

public InputStream getInputStream()
                           throws IOException
Description copied from interface: RandomAccessInput
Return the input as an InputStream.

Returns:
An InputStream containing the input contents.
Throws:
IOException - If an I/O error occurs.


Copyright © 2017. All rights reserved.