org.foray.common.io
Class AbstractRandomAccessInput

java.lang.Object
  extended by org.foray.common.io.AbstractRandomAccessInput
All Implemented Interfaces:
DataInput, RandomAccessInput
Direct Known Subclasses:
RandomAccessInputArray, RandomAccessInputFile, RandomAccessInputURL

public abstract class AbstractRandomAccessInput
extends Object
implements RandomAccessInput

Abstract superclass for RandomAccessInput implementations.


Constructor Summary
AbstractRandomAccessInput()
           
 
Method Summary
static RandomAccessInput createRandomAccessInput(DataSource dataSource)
          Factory method that creates an instance of the best RandomAccessInput implementation for a given byte array.
static RandomAccessInput createRandomAccessInput(String description, byte[] byteArray)
          Factory method that creates an instance of the best RandomAccessInput implementation for a given byte array.
static RandomAccessInput createRandomAccessInput(URL url)
          Factory method that creates an instance of the best RandomAccessInput implementation for a given URL.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.foray.common.io.RandomAccessInput
getDescription, getInputStream, getOffset, length, seek
 
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
 

Constructor Detail

AbstractRandomAccessInput

public AbstractRandomAccessInput()
Method Detail

createRandomAccessInput

public static RandomAccessInput createRandomAccessInput(URL url)
                                                 throws IOException
Factory method that creates an instance of the best RandomAccessInput implementation for a given URL.

Parameters:
url - The URL for which a RandomAccessInput instance is needed.
Returns:
The newly-created RandomAccessInput instance.
Throws:
IOException - For errors opening or reading the URL.

createRandomAccessInput

public static RandomAccessInput createRandomAccessInput(String description,
                                                        byte[] byteArray)
Factory method that creates an instance of the best RandomAccessInput implementation for a given byte array.

Parameters:
description - The description of the byte array.
byteArray - The byte array for which a RandomAccessInput instance is needed.
Returns:
The newly-created RandomAccessInput instance.

createRandomAccessInput

public static RandomAccessInput createRandomAccessInput(DataSource dataSource)
                                                 throws IOException
Factory method that creates an instance of the best RandomAccessInput implementation for a given byte array.

Parameters:
dataSource - The data source containing the description and content.
Returns:
The newly-created RandomAccessInput instance.
Throws:
IOException - For errors opening or reading the input stream.

readUnsignedInt

public final long readUnsignedInt()
                           throws IOException
Description copied from interface: RandomAccessInput
Read 4 unsigned bytes and convert them to a long containing the unsigned value.

Specified by:
readUnsignedInt in interface RandomAccessInput
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

public long readUnsignedIntLoHi()
                         throws IOException
Description copied from interface: RandomAccessInput
Read an unsigned 4-byte integer, and reverse the byte order, making the lowest-order byte first and the highest-order byte last.

Specified by:
readUnsignedIntLoHi in interface RandomAccessInput
Returns:
The unsigned integral.
Throws:
IOException - For I/O error.

readUnsignedShortLoHi

public int readUnsignedShortLoHi()
                          throws IOException
Description copied from interface: RandomAccessInput
Read an unsigned 2-byte short, and reverse the byte order, making the low-order byte first and the high-order byte last.

Specified by:
readUnsignedShortLoHi in interface RandomAccessInput
Returns:
The unsigned integral.
Throws:
IOException - For I/O error.

readShortLoHi

public int readShortLoHi()
                  throws IOException
Description copied from interface: RandomAccessInput
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.

Specified by:
readShortLoHi in interface RandomAccessInput
Returns:
The unsigned integral.
Throws:
IOException - For I/O error.

readString

public String readString(int stringSize,
                         Charset characterSet)
                  throws IOException
Description copied from interface: RandomAccessInput
Reads a String of stringSize bytes at the current location.

Specified by:
readString in interface RandomAccessInput
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

public String readStringASCII(int stringSize)
                       throws IOException
Description copied from interface: RandomAccessInput
Reads an ASCII String of stringSize bytes at the current location.

Specified by:
readStringASCII in interface RandomAccessInput
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

public String readTerminatedString(byte terminatingChar,
                                   Charset characterSet)
                            throws IOException
Description copied from interface: RandomAccessInput
Reads a string terminated by a specific character, usually the null character, 0x00.

Specified by:
readTerminatedString in interface RandomAccessInput
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

public String readNullTerminatedString(Charset characterSet)
                                throws IOException
Description copied from interface: RandomAccessInput
Reads a null-terminated String.

Specified by:
readNullTerminatedString in interface RandomAccessInput
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.

readFixed16x16Signed

public BigDecimal readFixed16x16Signed()
                                throws IOException
Description copied from interface: RandomAccessInput
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).

Specified by:
readFixed16x16Signed in interface RandomAccessInput
Returns:
The parsed value, as a BigDecimal.
Throws:
IOException - For I/O Error.


Copyright © 2017. All rights reserved.