public class TLcdDataInputStream extends Object implements DataInput, AutoCloseable
The position is incremented before the read operations, so it will be incremented even if the operation fails.
Modifier and Type | Field and Description |
---|---|
protected int |
fBitPosition
Position within a byte.
|
protected DataInputStream |
fDataInputStream
Encapsulated DataInputStream object.
|
protected boolean |
fLittleEndianMode
Specifies whether pairs of bytes in the data stream should be interpreted as
little endian, i.e. with the least significant byte first.
|
protected boolean |
fLittleEndianWordMode
Specifies whether pairs of words in the data stream should be interpreted as
little endian, i.e. with the least significant word first.
|
protected long |
fMarkPosition
Last marked valid position.
|
protected long |
fPosition
Position in the data stream.
|
Constructor and Description |
---|
TLcdDataInputStream(InputStream aInputStream)
Constructs a
TLcdDataInputStream based on an InputStream. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the data stream.
|
long |
getPosition()
Returns the position in the data stream.
|
boolean |
isLittleEndianMode()
Returns true if the numbers read from the stream are interpreted in little endian format.
|
boolean |
isLittleEndianWordMode()
Returns whether the words in the data stream are interpreted as little endian.
|
void |
mark(int aReadLimit)
Marks the current position in this input stream.
|
boolean |
markSupported()
Tests if the data stream supports the
mark and reset methods. |
int |
read(byte[] aBuffer)
Bytes for this operation are read from the contained
input stream.
|
int |
read(byte[] aBuffer,
int aOffset,
int aLength)
Bytes for this operation are read from the contained input stream.
|
double |
readBIDouble()
Reads a big-endian double.
|
float |
readBIFloat()
Reads a big-endian float.
|
int |
readBIInt()
Reads a big-endian integer.
|
long |
readBILong()
Reads a big-endian long.
|
short |
readBIShort()
Reads a big-endian short.
|
boolean |
readBoolean() |
byte |
readByte()
Reads a byte from the contained input stream.
|
char |
readChar()
Reads a char in big or little endian mode.
|
double |
readDouble()
Reads an double in big or little endian mode.
|
float |
readFloat()
Reads an float in big or little endian mode.
|
void |
readFully(byte[] aBuffer)
Bytes for this operation are read from the contained input stream.
|
void |
readFully(byte[] aBuffer,
int aOffset,
int aLength)
Bytes for this operation are read from the contained input stream.
|
int |
readInt()
Reads an integer in big or little endian mode.
|
int |
readInt(int aByteCount)
Reads a little endian integer of the given number of bytes.
|
double |
readLIDouble()
Reads a little-endian double.
|
float |
readLIFloat()
Reads a little-endian float.
|
int |
readLIInt()
Reads a little-endian integer.
|
long |
readLILong()
Reads a little-endian long.
|
String |
readLine()
Reads the next line from the contained input stream.
|
short |
readLIShort()
Reads a little-endian short.
|
long |
readLong()
Reads an long in big or little endian mode.
|
short |
readShort()
Reads a short in big or little endian mode.
|
int |
readUnsignedByte()
Reads an unsigned byte from the contained input stream.
|
long |
readUnsignedInt()
Reads a unsigned int in big or little endian mode.
|
int |
readUnsignedShort()
Reads a unsigned short in big or little endian mode.
|
String |
readUTF()
Reads a Unicode string from the contained input stream.
|
static String |
readUTF(DataInput aDataInput)
Reads a Unicode character from the data stream.
|
void |
reset()
Resets the data streams to its last marked valid position.
|
void |
resetPosition()
Resets the position to 0.
|
void |
setLittleEndianMode(boolean aFlag)
Specifies whether numbers read from the stream should be interpreted in little endian format.
|
void |
setLittleEndianWordMode(boolean aFlag)
Specifies whether pairs of words in the data stream should be interpreted as
little endian, i.e. with the least significant word first.
|
int |
skipBytes(int n)
Bytes for this operation are read from the contained input stream.
|
long |
skipBytes(long n)
Attempts to skip over
n bytes
of data from the input stream, discarding the skipped bytes. |
protected DataInputStream fDataInputStream
protected boolean fLittleEndianMode
true
on construction.protected boolean fLittleEndianWordMode
true
on construction.protected long fPosition
protected long fMarkPosition
protected int fBitPosition
public TLcdDataInputStream(InputStream aInputStream)
TLcdDataInputStream
based on an InputStream.aInputStream
- the InputStream to encapsulate.public final void setLittleEndianMode(boolean aFlag)
true
.aFlag
- true when numbers read from the stream should be interpreted in little endian format.public final boolean isLittleEndianMode()
public final void setLittleEndianWordMode(boolean aFlag)
true
.aFlag
- whether to interpret the words in the data stream as little endian.public final boolean isLittleEndianWordMode()
public final long getPosition()
public final void resetPosition()
public final short readShort() throws IOException
readShort
in interface DataInput
IOException
- if an I/O error occurs.public final short readBIShort() throws IOException
IOException
- if an I/O error occurs.public final short readLIShort() throws IOException
IOException
- if an I/O error occurs.public final int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
- if an I/O error occurs.public final char readChar() throws IOException
readChar
in interface DataInput
IOException
- if an I/O error occurs.public final int readInt() throws IOException
readInt
in interface DataInput
IOException
- if an I/O error occurs.public final int readBIInt() throws IOException
IOException
- if an I/O error occurs.public final int readLIInt() throws IOException
IOException
- if an I/O error occurs.public final long readUnsignedInt() throws IOException
IOException
- if an I/O error occurs.public final int readInt(int aByteCount) throws IOException
aByteCount
- the number of bytes to read.IOException
- if an I/O error occurs.public final long readLong() throws IOException
readLong
in interface DataInput
IOException
- if an I/O error occurs.public final long readBILong() throws IOException
IOException
- if an I/O error occurs.public final long readLILong() throws IOException
IOException
- if an I/O error occurs.public final float readFloat() throws IOException
readFloat
in interface DataInput
IOException
- if an I/O error occurs.public final float readBIFloat() throws IOException
IOException
- if an I/O error occurs.public final float readLIFloat() throws IOException
IOException
- if an I/O error occurs.public final double readDouble() throws IOException
readDouble
in interface DataInput
IOException
- if an I/O error occurs.public final double readBIDouble() throws IOException
IOException
- if an I/O error occurs.public final double readLIDouble() throws IOException
IOException
- if an I/O error occurs.public final int read(byte[] aBuffer) throws IOException
read(aBuffer, 0, aBuffer.length)
;aBuffer
- the buffer into which the data is read.-1
if there is no more data because the end
of the stream has been reached.IOException
- if an I/O error occurs.public final int read(byte[] aBuffer, int aOffset, int aLength) throws IOException
aLength
number of bytes are read, even when the contained input stream has enough data.
Use readFully(byte[], int, int)
for this.aBuffer
- the buffer into which the data is read.aOffset
- the start offset of the data.aLength
- the maximum number of bytes read.-1
if there is no more data because the end
of the stream has been reached.IOException
- if an I/O error occurs.public final void readFully(byte[] aBuffer) throws IOException
readFully
in interface DataInput
aBuffer
- the buffer into which the data is read.IOException
- if an I/O error occurs.public final void readFully(byte[] aBuffer, int aOffset, int aLength) throws IOException
readFully
in interface DataInput
aBuffer
- the buffer into which the data is read.aOffset
- the start offset of the data.aLength
- the number of bytes to read completely.IOException
- if an I/O error occurs.public final int skipBytes(int n) throws IOException
skipBytes
in interface DataInput
n
- the number of bytes to be skipped.IOException
- if an I/O error occurs.public final boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public final byte readByte() throws IOException
readByte
in interface DataInput
byte
value read.IOException
- if an I/O error occurs.public final int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
byte
value read.IOException
- if an I/O error occurs.public final String readLine() throws IOException
readLine
in interface DataInput
IOException
- if an I/O error occurs.public final String readUTF() throws IOException
readUTF
in interface DataInput
IOException
- if an I/O error occurs.public static String readUTF(DataInput aDataInput) throws IOException
aDataInput
- a data input stream.IOException
- if an I/O error occurs.public boolean markSupported()
mark
and reset
methods.true
if the data stream type supports the mark
and reset
method;
false
otherwise.public void mark(int aReadLimit)
reset
method repositions this stream at
the last marked position so that subsequent reads re-read the same bytes.
The aReadLimit
argument tells this input stream to
allow that many bytes to be read before the mark position gets
invalidated.
aReadLimit
- the maximum limit of bytes that can be read before
the mark position becomes invalid.public void reset() throws IOException
IOException
- if an I/O error occurs.public long skipBytes(long n) throws IOException
n
bytes
of data from the input stream, discarding the skipped bytes.
This method never throws an EOFException
.
The actual number of bytes skipped is returned.n
- the number of bytes to be skipped. Must be positive because the input stream might not support going back.IOException
public final void close() throws IOException
close
in interface AutoCloseable
IOException
- if an I/O error occurs.