Package com.luciad.io
Class TLcdDataInputStream
java.lang.Object
com.luciad.io.TLcdDataInputStream
- All Implemented Interfaces:
DataInput
,AutoCloseable
This class is similar to a DataInputStream, except that it can also read
little-endian binary data instead of only big-endian data.
The position is incremented before the read operations, so it will be incremented even if the operation fails.
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
Position within a byte.protected DataInputStream
Encapsulated DataInputStream object.protected boolean
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
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
Last marked valid position.protected long
Position in the data stream. -
Constructor Summary
ConstructorDescriptionTLcdDataInputStream
(InputStream aInputStream) Constructs aTLcdDataInputStream
based on an InputStream. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
close()
Closes the data stream.final long
Returns the position in the data stream.final boolean
Returns true if the numbers read from the stream are interpreted in little endian format.final boolean
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
Tests if the data stream supports themark
andreset
methods.final int
read
(byte[] aBuffer) Bytes for this operation are read from the contained input stream.final int
read
(byte[] aBuffer, int aOffset, int aLength) Bytes for this operation are read from the contained input stream.final double
Reads a big-endian double.final float
Reads a big-endian float.final int
Reads a big-endian integer.final long
Reads a big-endian long.final short
Reads a big-endian short.final boolean
final byte
readByte()
Reads a byte from the contained input stream.final char
readChar()
Reads a char in big or little endian mode.final double
Reads an double in big or little endian mode.final float
Reads an float in big or little endian mode.final void
readFully
(byte[] aBuffer) Bytes for this operation are read from the contained input stream.final void
readFully
(byte[] aBuffer, int aOffset, int aLength) Bytes for this operation are read from the contained input stream.final int
readInt()
Reads an integer in big or little endian mode.final int
readInt
(int aByteCount) Reads a little endian integer of the given number of bytes.final double
Reads a little-endian double.final float
Reads a little-endian float.final int
Reads a little-endian integer.final long
Reads a little-endian long.final String
readLine()
Deprecated.This method does not properly convert bytes to characters.final short
Reads a little-endian short.final long
readLong()
Reads an long in big or little endian mode.final short
Reads a short in big or little endian mode.final int
Reads an unsigned byte from the contained input stream.final long
Reads a unsigned int in big or little endian mode.final int
Reads a unsigned short in big or little endian mode.final String
readUTF()
Reads a Unicode string from the contained input stream.static String
Reads a Unicode character from the data stream.void
reset()
Resets the data streams to its last marked valid position.final void
Resets the position to 0.final void
setLittleEndianMode
(boolean aFlag) Specifies whether numbers read from the stream should be interpreted in little endian format.final 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.final int
skipBytes
(int n) Bytes for this operation are read from the contained input stream.long
skipBytes
(long n) Attempts to skip overn
bytes of data from the input stream, discarding the skipped bytes.
-
Field Details
-
fDataInputStream
Encapsulated DataInputStream object. All reads are redirected to this object. -
fLittleEndianMode
protected boolean fLittleEndianModeSpecifies whether pairs of bytes in the data stream should be interpreted as little endian, i.e. with the least significant byte first.true
on construction. -
fLittleEndianWordMode
protected boolean fLittleEndianWordModeSpecifies whether pairs of words in the data stream should be interpreted as little endian, i.e. with the least significant word first.true
on construction. -
fPosition
protected long fPositionPosition in the data stream. -
fMarkPosition
protected long fMarkPositionLast marked valid position. -
fBitPosition
protected int fBitPositionPosition within a byte.
-
-
Constructor Details
-
TLcdDataInputStream
Constructs aTLcdDataInputStream
based on an InputStream.- Parameters:
aInputStream
- the InputStream to encapsulate.
-
-
Method Details
-
setLittleEndianMode
public final void setLittleEndianMode(boolean aFlag) Specifies whether numbers read from the stream should be interpreted in little endian format. In little endian format, the data stream stores the least significant byte first (lowest address) and the most significant byte last (highest address). The default istrue
.- Parameters:
aFlag
- true when numbers read from the stream should be interpreted in little endian format.
-
isLittleEndianMode
public final boolean isLittleEndianMode()Returns true if the numbers read from the stream are interpreted in little endian format. In little endian format, the data stream stores the least significant byte first (lowest address) and the most significant byte last (highest address).- Returns:
- true if the numbers read from the stream are interpreted in little endian format.
-
setLittleEndianWordMode
public final 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. In this context, a word refers to a pair of bytes. The pairs of bytes can be big endian or little endian, independently of this property. The default istrue
.- Parameters:
aFlag
- whether to interpret the words in the data stream as little endian.
-
isLittleEndianWordMode
public final boolean isLittleEndianWordMode()Returns whether the words in the data stream are interpreted as little endian.- Returns:
- whether the words in the data stream are interpreted as little endian.
-
getPosition
public final long getPosition()Returns the position in the data stream.- Returns:
- the position in the data stream.
-
resetPosition
public final void resetPosition()Resets the position to 0. -
readShort
Reads a short in big or little endian mode.- Specified by:
readShort
in interfaceDataInput
- Returns:
- the short read.
- Throws:
IOException
- if an I/O error occurs.
-
readBIShort
Reads a big-endian short.- Returns:
- the short read.
- Throws:
IOException
- if an I/O error occurs.
-
readLIShort
Reads a little-endian short.- Returns:
- the short read.
- Throws:
IOException
- if an I/O error occurs.
-
readUnsignedShort
Reads a unsigned short in big or little endian mode.- Specified by:
readUnsignedShort
in interfaceDataInput
- Returns:
- the unsigned short read.
- Throws:
IOException
- if an I/O error occurs.
-
readChar
Reads a char in big or little endian mode.- Specified by:
readChar
in interfaceDataInput
- Returns:
- the char read.
- Throws:
IOException
- if an I/O error occurs.
-
readInt
Reads an integer in big or little endian mode.- Specified by:
readInt
in interfaceDataInput
- Returns:
- the integer read.
- Throws:
IOException
- if an I/O error occurs.
-
readBIInt
Reads a big-endian integer.- Returns:
- the integer read.
- Throws:
IOException
- if an I/O error occurs.
-
readLIInt
Reads a little-endian integer.- Returns:
- the integer read.
- Throws:
IOException
- if an I/O error occurs.
-
readUnsignedInt
Reads a unsigned int in big or little endian mode.- Returns:
- the unsigned int read.
- Throws:
IOException
- if an I/O error occurs.
-
readInt
Reads a little endian integer of the given number of bytes.- Parameters:
aByteCount
- the number of bytes to read.- Returns:
- the little endian integer read.
- Throws:
IOException
- if an I/O error occurs.
-
readLong
Reads an long in big or little endian mode.- Specified by:
readLong
in interfaceDataInput
- Returns:
- the long read.
- Throws:
IOException
- if an I/O error occurs.
-
readBILong
Reads a big-endian long.- Returns:
- the long read.
- Throws:
IOException
- if an I/O error occurs.
-
readLILong
Reads a little-endian long.- Returns:
- the long read.
- Throws:
IOException
- if an I/O error occurs.
-
readFloat
Reads an float in big or little endian mode.- Specified by:
readFloat
in interfaceDataInput
- Returns:
- the float read.
- Throws:
IOException
- if an I/O error occurs.
-
readBIFloat
Reads a big-endian float.- Returns:
- the float read.
- Throws:
IOException
- if an I/O error occurs.
-
readLIFloat
Reads a little-endian float.- Returns:
- the float read.
- Throws:
IOException
- if an I/O error occurs.
-
readDouble
Reads an double in big or little endian mode.- Specified by:
readDouble
in interfaceDataInput
- Returns:
- the double read.
- Throws:
IOException
- if an I/O error occurs.
-
readBIDouble
Reads a big-endian double.- Returns:
- the double read.
- Throws:
IOException
- if an I/O error occurs.
-
readLIDouble
Reads a little-endian double.- Returns:
- the double read.
- Throws:
IOException
- if an I/O error occurs.
-
read
Bytes for this operation are read from the contained input stream. Calling this method is equivalent of callingread(aBuffer, 0, aBuffer.length)
;- Parameters:
aBuffer
- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the stream has been reached. - Throws:
IOException
- if an I/O error occurs.
-
read
Bytes for this operation are read from the contained input stream. There is no guarantee thataLength
number of bytes are read, even when the contained input stream has enough data. UsereadFully(byte[], int, int)
for this.- Parameters:
aBuffer
- the buffer into which the data is read.aOffset
- the start offset of the data.aLength
- the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the stream has been reached. - Throws:
IOException
- if an I/O error occurs.
-
readFully
Bytes for this operation are read from the contained input stream.- Specified by:
readFully
in interfaceDataInput
- Parameters:
aBuffer
- the buffer into which the data is read.- Throws:
IOException
- if an I/O error occurs.
-
readFully
Bytes for this operation are read from the contained input stream.- Specified by:
readFully
in interfaceDataInput
- Parameters:
aBuffer
- the buffer into which the data is read.aOffset
- the start offset of the data.aLength
- the number of bytes to read completely.- Throws:
IOException
- if an I/O error occurs.
-
skipBytes
Bytes for this operation are read from the contained input stream.- Specified by:
skipBytes
in interfaceDataInput
- Parameters:
n
- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException
- if an I/O error occurs.
-
readBoolean
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readByte
Reads a byte from the contained input stream.- Specified by:
readByte
in interfaceDataInput
- Returns:
- the
byte
value read. - Throws:
IOException
- if an I/O error occurs.
-
readUnsignedByte
Reads an unsigned byte from the contained input stream.- Specified by:
readUnsignedByte
in interfaceDataInput
- Returns:
- the unsigned
byte
value read. - Throws:
IOException
- if an I/O error occurs.
-
readLine
Deprecated.This method does not properly convert bytes to characters. SeeDataInputStream.readLine()
for more information.Reads the next line from the contained input stream.- Specified by:
readLine
in interfaceDataInput
- Returns:
- the next line of text from this input stream.
- Throws:
IOException
- if an I/O error occurs.
-
readUTF
Reads a Unicode string from the contained input stream.- Specified by:
readUTF
in interfaceDataInput
- Returns:
- a Unicode string.
- Throws:
IOException
- if an I/O error occurs.
-
readUTF
Reads a Unicode character from the data stream.- Parameters:
aDataInput
- a data input stream.- Returns:
- a Unicode string.
- Throws:
IOException
- if an I/O error occurs.
-
markSupported
public boolean markSupported()Tests if the data stream supports themark
andreset
methods.- Returns:
true
if the data stream type supports themark
andreset
method;false
otherwise.
-
mark
public void mark(int aReadLimit) Marks the current position in this input stream. A subsequent call to thereset
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.- Parameters:
aReadLimit
- the maximum limit of bytes that can be read before the mark position becomes invalid.
-
reset
Resets the data streams to its last marked valid position.- Throws:
IOException
- if an I/O error occurs.
-
skipBytes
Attempts to skip overn
bytes of data from the input stream, discarding the skipped bytes. This method never throws anEOFException
. The actual number of bytes skipped is returned.- Parameters:
n
- the number of bytes to be skipped. Must be positive because the input stream might not support going back.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException
- Since:
- 2018.0
-
close
Closes the data stream.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- if an I/O error occurs.
-