Package com.drew.lang
Class SequentialReader
- java.lang.Object
-
- com.drew.lang.SequentialReader
-
- Direct Known Subclasses:
SequentialByteArrayReader,StreamReader
public abstract class SequentialReader extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description SequentialReader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract intavailable()Returns an estimate of the number of bytes that can be read (or skipped over) from thisSequentialReaderwithout blocking by the next invocation of a method for this input stream.abstract bytegetByte()Gets the next byte in the sequence.abstract voidgetBytes(byte[] buffer, int offset, int count)Retrieves bytes, writing them into a caller-provided buffer.abstract byte[]getBytes(int count)Returns the required number of bytes from the sequence.doublegetDouble64()floatgetFloat32()shortgetInt16()Returns a signed 16-bit int calculated from two bytes of data (MSB, LSB).intgetInt32()Returns a signed 32-bit integer from four bytes of data.longgetInt64()Get a signed 64-bit integer from the buffer.bytegetInt8()Returns a signed 8-bit int calculated from the next byte the sequence.byte[]getNullTerminatedBytes(int maxLengthBytes)Returns the sequence of bytes punctuated by a\0value.java.lang.StringgetNullTerminatedString(int maxLengthBytes, java.nio.charset.Charset charset)Creates a String from the stream, ending wherebyte=='\0'or wherelength==maxLength.StringValuegetNullTerminatedStringValue(int maxLengthBytes, java.nio.charset.Charset charset)Creates a String from the stream, ending wherebyte=='\0'or wherelength==maxLength.abstract longgetPosition()floatgetS15Fixed16()Gets a s15.16 fixed point float from the buffer.java.lang.StringgetString(int bytesRequested)java.lang.StringgetString(int bytesRequested, java.lang.String charset)java.lang.StringgetString(int bytesRequested, java.nio.charset.Charset charset)StringValuegetStringValue(int bytesRequested, java.nio.charset.Charset charset)intgetUInt16()Returns an unsigned 16-bit int calculated from the next two bytes of the sequence.longgetUInt32()Get a 32-bit unsigned integer from the buffer, returning it as a long.shortgetUInt8()Returns an unsigned 8-bit int calculated from the next byte of the sequence.booleanisMotorolaByteOrder()Gets the endianness of this reader.voidsetMotorolaByteOrder(boolean motorolaByteOrder)Sets the endianness of this reader.abstract voidskip(long n)Skips forward in the sequence.abstract booleantrySkip(long n)Skips forward in the sequence, returning a boolean indicating whether the skip succeeded, or whether the sequence ended.
-
-
-
Method Detail
-
getPosition
public abstract long getPosition() throws java.io.IOException- Throws:
java.io.IOException
-
getByte
public abstract byte getByte() throws java.io.IOExceptionGets the next byte in the sequence.- Returns:
- The read byte value
- Throws:
java.io.IOException
-
getBytes
public abstract byte[] getBytes(int count) throws java.io.IOExceptionReturns the required number of bytes from the sequence.- Parameters:
count- The number of bytes to be returned- Returns:
- The requested bytes
- Throws:
java.io.IOException
-
getBytes
public abstract void getBytes(byte[] buffer, int offset, int count) throws java.io.IOExceptionRetrieves bytes, writing them into a caller-provided buffer.- Parameters:
buffer- The array to write bytes to.offset- The starting position within buffer to write to.count- The number of bytes to be written.- Throws:
java.io.IOException
-
skip
public abstract void skip(long n) throws java.io.IOExceptionSkips forward in the sequence. If the sequence ends, anEOFExceptionis thrown.- Parameters:
n- the number of byte to skip. Must be zero or greater.- Throws:
java.io.EOFException- the end of the sequence is reached.java.io.IOException- an error occurred reading from the underlying source.
-
trySkip
public abstract boolean trySkip(long n) throws java.io.IOExceptionSkips forward in the sequence, returning a boolean indicating whether the skip succeeded, or whether the sequence ended.- Parameters:
n- the number of byte to skip. Must be zero or greater.- Returns:
- a boolean indicating whether the skip succeeded, or whether the sequence ended.
- Throws:
java.io.IOException- an error occurred reading from the underlying source.
-
available
public abstract int available()
Returns an estimate of the number of bytes that can be read (or skipped over) from thisSequentialReaderwithout blocking by the next invocation of a method for this input stream. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.Note that while some implementations of
SequentialReaderlikeSequentialByteArrayReaderwill return the total remaining number of bytes in the stream, others will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.- Returns:
- an estimate of the number of bytes that can be read (or skipped
over) from this
SequentialReaderwithout blocking or0when it reaches the end of the input stream.
-
setMotorolaByteOrder
public void setMotorolaByteOrder(boolean motorolaByteOrder)
Sets the endianness of this reader.truefor Motorola (or big) endianness (also known as network byte order), with MSB before LSB.falsefor Intel (or little) endianness, with LSB before MSB.
- Parameters:
motorolaByteOrder-truefor Motorola/big endian,falsefor Intel/little endian
-
isMotorolaByteOrder
public boolean isMotorolaByteOrder()
Gets the endianness of this reader.truefor Motorola (or big) endianness (also known as network byte order), with MSB before LSB.falsefor Intel (or little) endianness, with LSB before MSB.
-
getUInt8
public short getUInt8() throws java.io.IOExceptionReturns an unsigned 8-bit int calculated from the next byte of the sequence.- Returns:
- the 8 bit int value, between 0 and 255
- Throws:
java.io.IOException
-
getInt8
public byte getInt8() throws java.io.IOExceptionReturns a signed 8-bit int calculated from the next byte the sequence.- Returns:
- the 8 bit int value, between 0x00 and 0xFF
- Throws:
java.io.IOException
-
getUInt16
public int getUInt16() throws java.io.IOExceptionReturns an unsigned 16-bit int calculated from the next two bytes of the sequence.- Returns:
- the 16 bit int value, between 0x0000 and 0xFFFF
- Throws:
java.io.IOException
-
getInt16
public short getInt16() throws java.io.IOExceptionReturns a signed 16-bit int calculated from two bytes of data (MSB, LSB).- Returns:
- the 16 bit int value, between 0x0000 and 0xFFFF
- Throws:
java.io.IOException- the buffer does not contain enough bytes to service the request
-
getUInt32
public long getUInt32() throws java.io.IOExceptionGet a 32-bit unsigned integer from the buffer, returning it as a long.- Returns:
- the unsigned 32-bit int value as a long, between 0x00000000 and 0xFFFFFFFF
- Throws:
java.io.IOException- the buffer does not contain enough bytes to service the request
-
getInt32
public int getInt32() throws java.io.IOExceptionReturns a signed 32-bit integer from four bytes of data.- Returns:
- the signed 32 bit int value, between 0x00000000 and 0xFFFFFFFF
- Throws:
java.io.IOException- the buffer does not contain enough bytes to service the request
-
getInt64
public long getInt64() throws java.io.IOExceptionGet a signed 64-bit integer from the buffer.- Returns:
- the 64 bit int value, between 0x0000000000000000 and 0xFFFFFFFFFFFFFFFF
- Throws:
java.io.IOException- the buffer does not contain enough bytes to service the request
-
getS15Fixed16
public float getS15Fixed16() throws java.io.IOExceptionGets a s15.16 fixed point float from the buffer.This particular fixed point encoding has one sign bit, 15 numerator bits and 16 denominator bits.
- Returns:
- the floating point value
- Throws:
java.io.IOException- the buffer does not contain enough bytes to service the request
-
getFloat32
public float getFloat32() throws java.io.IOException- Throws:
java.io.IOException
-
getDouble64
public double getDouble64() throws java.io.IOException- Throws:
java.io.IOException
-
getString
public java.lang.String getString(int bytesRequested) throws java.io.IOException- Throws:
java.io.IOException
-
getString
public java.lang.String getString(int bytesRequested, java.lang.String charset) throws java.io.IOException- Throws:
java.io.IOException
-
getString
public java.lang.String getString(int bytesRequested, java.nio.charset.Charset charset) throws java.io.IOException- Throws:
java.io.IOException
-
getStringValue
public StringValue getStringValue(int bytesRequested, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
java.io.IOException
-
getNullTerminatedString
public java.lang.String getNullTerminatedString(int maxLengthBytes, java.nio.charset.Charset charset) throws java.io.IOExceptionCreates a String from the stream, ending wherebyte=='\0'or wherelength==maxLength.- Parameters:
maxLengthBytes- The maximum number of bytes to read. If a zero-byte is not reached within this limit, reading will stop and the string will be truncated to this length.- Returns:
- The read string.
- Throws:
java.io.IOException- The buffer does not contain enough bytes to satisfy this request.
-
getNullTerminatedStringValue
public StringValue getNullTerminatedStringValue(int maxLengthBytes, java.nio.charset.Charset charset) throws java.io.IOException
Creates a String from the stream, ending wherebyte=='\0'or wherelength==maxLength.- Parameters:
maxLengthBytes- The maximum number of bytes to read. If a\0byte is not reached within this limit, reading will stop and the string will be truncated to this length.charset- TheCharsetto register with the returnedStringValue, ornullif the encoding is unknown- Returns:
- The read string.
- Throws:
java.io.IOException- The buffer does not contain enough bytes to satisfy this request.
-
getNullTerminatedBytes
public byte[] getNullTerminatedBytes(int maxLengthBytes) throws java.io.IOExceptionReturns the sequence of bytes punctuated by a\0value.- Parameters:
maxLengthBytes- The maximum number of bytes to read. If a\0byte is not reached within this limit, the returned array will bemaxLengthByteslong.- Returns:
- The read byte array, excluding the null terminator.
- Throws:
java.io.IOException- The buffer does not contain enough bytes to satisfy this request.
-
-