org.foray.common.io
Interface RandomAccessInput

All Superinterfaces:
DataInput
All Known Implementing Classes:
AbstractRandomAccessInput, RandomAccessInputArray, RandomAccessInputFile, RandomAccessInputURL

public interface RandomAccessInput
extends DataInput

This interface extends DataInput by adding methods for random access to the contents. The method names and signatures were pulled up from RandomAccessFile. This interface will generally be useful for classes providing random input access to a file or file-like structure, i.e. file readers or parsers.

See Also:
DataInput, RandomAccessFile

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.
 BigDecimal readFixed16x16Signed()
          Reads a fixed-length decimal number with a 16-bit signed twos-complement mantissa, followed by a 16-bit unsigned fraction.
 String readNullTerminatedString(Charset characterSet)
          Reads a null-terminated String.
 int readShortLoHi()
          Read a signed 2-byte short in little-endian order, that is, making the first byte the low-order byte and the second byte the high-order byte.
 String readString(int stringSize, Charset characterSet)
          Reads a String of stringSize bytes at the current location.
 String readStringASCII(int stringSize)
          Reads an ASCII String of stringSize bytes at the current location.
 String readTerminatedString(byte terminatingChar, Charset characterSet)
          Reads a string terminated by a specific character, usually the null character, 0x00.
 long readUnsignedInt()
          Read 4 unsigned bytes and convert them to a long containing the unsigned value.
 long readUnsignedIntLoHi()
          Read an unsigned 4-byte integer, and reverse the byte order, making the lowest-order byte first and the highest-order byte last.
 int readUnsignedShortLoHi()
          Read an unsigned 2-byte short, and reverse the byte order, making the low-order byte first and the high-order byte last.
 void seek(long offset)
          Sets the input pointer offset, measured from the beginning of the input, at which the next read occurs.
 
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
 

Method Detail

seek

void seek(long offset)
          throws IOException

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)

getOffset

long getOffset()
               throws IOException

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()

length

long length()
            throws IOException

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()

getDescription

String getDescription()
Provides some kind of description of this item, useful in user messages.

Returns:
A description of the contents of this item.

getInputStream

InputStream getInputStream()
                           throws IOException
Return the input as an InputStream.

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

readString

String readString(int stringSize,
                  Charset characterSet)
                  throws IOException
Reads a String of stringSize bytes at the current location.

Parameters:
stringSize - The length, in bytes, of the String to be read.
characterSet - The encoding scheme to be used for interpreting the characters in the string.
Returns:
The read String.
Throws:
IOException - For reading past the end of the input.

readStringASCII

String readStringASCII(int stringSize)
                       throws IOException
Reads an ASCII String of stringSize bytes at the current location.

Parameters:
stringSize - The length, in bytes, of the String to be read.
Returns:
The read String.
Throws:
IOException - For reading past the end of the input.

readTerminatedString

String readTerminatedString(byte terminatingChar,
                            Charset characterSet)
                            throws IOException
Reads a string terminated by a specific character, usually the null character, 0x00.

Parameters:
terminatingChar - The value to be used as the terminator for the read String.
characterSet - The encoding scheme to be used for interpreting the characters in the string.
Returns:
The string read.
Throws:
IOException - For I/O error.

readNullTerminatedString

String readNullTerminatedString(Charset characterSet)
                                throws IOException
Reads a null-terminated String.

Parameters:
characterSet - The encoding scheme to be used for interpreting the characters in the string.
Returns:
The read String.
Throws:
IOException - For I/O error.

readUnsignedInt

long readUnsignedInt()
                     throws IOException
Read 4 unsigned bytes and convert them to a long containing the unsigned value.

Returns:
A long containing the unsigned 32-bit value. Returns a long because int is signed, and therefore can't hold 32 unsigned bits.
Throws:
IOException - For I/O error.

readUnsignedIntLoHi

long readUnsignedIntLoHi()
                         throws IOException
Read an unsigned 4-byte integer, and reverse the byte order, making the lowest-order byte first and the highest-order byte last.

Returns:
The unsigned integral.
Throws:
IOException - For I/O error.

readUnsignedShortLoHi

int readUnsignedShortLoHi()
                          throws IOException
Read an unsigned 2-byte short, and reverse the byte order, making the low-order byte first and the high-order byte last.

Returns:
The unsigned integral.
Throws:
IOException - For I/O error.

readShortLoHi

int readShortLoHi()
                  throws IOException
Read a signed 2-byte short in little-endian order, that is, making the first byte the low-order byte and the second byte the high-order byte.

Returns:
The unsigned integral.
Throws:
IOException - For I/O error.

readFixed16x16Signed

BigDecimal readFixed16x16Signed()
                                throws IOException
Reads a fixed-length decimal number with a 16-bit signed twos-complement mantissa, followed by a 16-bit unsigned fraction. Note that this format corresponds to a TrueType Font "FIXED" data type, as described in the TTF Spec, Chapter 2 (Data Types).

Returns:
The parsed value, as a BigDecimal.
Throws:
IOException - For I/O Error.


Copyright © 2017. All rights reserved.