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
FieldsModifier and TypeFieldDescriptionprotected intPosition within a byte.protected DataInputStreamEncapsulated DataInputStream object.protected booleanSpecifies whether pairs of bytes in the data stream should be interpreted as little endian, i.e. with the least significant byte first.protected booleanSpecifies whether pairs of words in the data stream should be interpreted as little endian, i.e. with the least significant word first.protected longLast marked valid position.protected longPosition in the data stream. -
Constructor Summary
ConstructorsConstructorDescriptionTLcdDataInputStream(InputStream aInputStream) Constructs aTLcdDataInputStreambased on an InputStream. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()Closes the data stream.final longReturns the position in the data stream.final booleanReturns true if the numbers read from the stream are interpreted in little endian format.final booleanReturns whether the words in the data stream are interpreted as little endian.voidmark(int aReadLimit) Marks the current position in this input stream.booleanTests if the data stream supports themarkandresetmethods.final intread(byte[] aBuffer) Bytes for this operation are read from the contained input stream.final intread(byte[] aBuffer, int aOffset, int aLength) Bytes for this operation are read from the contained input stream.final doubleReads a big-endian double.final floatReads a big-endian float.final intReads a big-endian integer.final longReads a big-endian long.final shortReads a big-endian short.final booleanfinal bytereadByte()Reads a byte from the contained input stream.final charreadChar()Reads a char in big or little endian mode.final doubleReads an double in big or little endian mode.final floatReads an float in big or little endian mode.final voidreadFully(byte[] aBuffer) Bytes for this operation are read from the contained input stream.final voidreadFully(byte[] aBuffer, int aOffset, int aLength) Bytes for this operation are read from the contained input stream.final intreadInt()Reads an integer in big or little endian mode.final intreadInt(int aByteCount) Reads a little endian integer of the given number of bytes.final doubleReads a little-endian double.final floatReads a little-endian float.final intReads a little-endian integer.final longReads a little-endian long.final StringreadLine()Deprecated.This method does not properly convert bytes to characters.final shortReads a little-endian short.final longreadLong()Reads an long in big or little endian mode.final shortReads a short in big or little endian mode.final intReads an unsigned byte from the contained input stream.final longReads a unsigned int in big or little endian mode.final intReads a unsigned short in big or little endian mode.final StringreadUTF()Reads a Unicode string from the contained input stream.static StringReads a Unicode character from the data stream.voidreset()Resets the data streams to its last marked valid position.final voidResets the position to 0.final voidsetLittleEndianMode(boolean aFlag) Specifies whether numbers read from the stream should be interpreted in little endian format.final voidsetLittleEndianWordMode(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 intskipBytes(int n) Bytes for this operation are read from the contained input stream.longskipBytes(long n) Attempts to skip overnbytes 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.trueon 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.trueon 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 aTLcdDataInputStreambased 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:
readShortin 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:
readUnsignedShortin 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:
readCharin 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:
readIntin 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:
readLongin 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:
readFloatin 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:
readDoublein 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
-1if 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 thataLengthnumber 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
-1if 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:
readFullyin 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:
readFullyin 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:
skipBytesin 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:
readBooleanin interfaceDataInput- Throws:
IOException
-
readByte
Reads a byte from the contained input stream.- Specified by:
readBytein interfaceDataInput- Returns:
- the
bytevalue read. - Throws:
IOException- if an I/O error occurs.
-
readUnsignedByte
Reads an unsigned byte from the contained input stream.- Specified by:
readUnsignedBytein interfaceDataInput- Returns:
- the unsigned
bytevalue 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:
readLinein 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:
readUTFin 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 themarkandresetmethods.- Returns:
trueif the data stream type supports themarkandresetmethod;falseotherwise.
-
mark
public void mark(int aReadLimit) Marks the current position in this input stream. A subsequent call to theresetmethod repositions this stream at the last marked position so that subsequent reads re-read the same bytes.The
aReadLimitargument 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 overnbytes 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:
closein interfaceAutoCloseable- Throws:
IOException- if an I/O error occurs.
-