org.foray.common.io
Class RandomAccessInputArray

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

public class RandomAccessInputArray
extends AbstractRandomAccessInput

Implementation of RandomInput that uses a byte array.


Constructor Summary
RandomAccessInputArray(String description, byte[] byteArray)
          Constructor.
RandomAccessInputArray(String description, InputStream inputStream)
          Constructor useful for providing access to the content of an input stream.
 
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

RandomAccessInputArray

public RandomAccessInputArray(String description,
                              byte[] byteArray)
Constructor.

Parameters:
description - A description of the source of this byte array, useful in user messages.
byteArray - The byte array which will be "read" by this reader.

RandomAccessInputArray

public RandomAccessInputArray(String description,
                              InputStream inputStream)
                       throws IOException
Constructor useful for providing access to the content of an input stream.

Parameters:
description - A description of the source of the input stream, useful in user messages.
inputStream - The input stream which will be "read" by this reader.
Throws:
IOException - For errors opening or reading the input stream.
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()
Description copied from interface: RandomAccessInput
Return the input as an InputStream.

Returns:
An InputStream containing the input contents.


Copyright © 2017. All rights reserved.