Class LittleEndianDataInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.twelvemonkeys.io.LittleEndianDataInputStream
- All Implemented Interfaces:
Closeable, DataInput, AutoCloseable
- Direct Known Subclasses:
CompoundDocument.SeekableLittleEndianDataInputStream
A little endian input stream reads two's complement,
little endian integers, floating point numbers, and characters
and returns them as Java primitive types.
The standard java.io.DataInputStream class
which this class imitates reads big endian quantities.
Warning:
The DataInput and DataOutput interfaces
specifies big endian byte order in their documentation.
This means that this class is, strictly speaking, not a proper
implementation. However, I don't see a reason for the these interfaces to
specify the byte order of their underlying representations.
- Version:
- 2
- See Also:
-
Field Summary
Fields inherited from class FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionLittleEndianDataInputStream(InputStream pStream) Creates a new little endian input stream and chains it to the input stream specified by thepStreamargument. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReads abooleanfrom the underlying input stream by reading a single byte.bytereadByte()Reads a signedbytefrom the underlying input stream with value between -128 and 127charreadChar()Reads a two byte Unicodecharfrom the underlying input stream in little endian order, low byte first.final doublefinal floatfinal voidreadFully(byte[] pBytes) See the general contract of thereadFullymethod ofDataInput.final voidreadFully(byte[] pBytes, int pOffset, int pLength) See the general contract of thereadFullymethod ofDataInput.intreadInt()Reads a four byte signedintfrom the underlying input stream in little endian order, low byte first.readLine()Deprecated.This method does not properly convert bytes to characters.longreadLong()Reads an eight byte signedintfrom the underlying input stream in little endian order, low byte first.shortReads a two byte signedshortfrom the underlying input stream in little endian order, low byte first.intReads an unsignedbytefrom the underlying input stream with value between 0 and 255intReads a two byte unsignedshortfrom the underlying input stream in little endian order, low byte first.readUTF()Reads a string of no more than 65,535 characters from the underlying input stream using UTF-8 encoding.final intskipBytes(int pLength) See the general contract of theskipBytesmethod ofDataInput.Methods inherited from class FilterInputStream
available, close, mark, markSupported, read, read, read, reset, skipMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
LittleEndianDataInputStream
Creates a new little endian input stream and chains it to the input stream specified by thepStreamargument.- Parameters:
pStream- the underlying input stream.- See Also:
-
-
Method Details
-
readBoolean
Reads abooleanfrom the underlying input stream by reading a single byte. If the byte is zero, false is returned. If the byte is positive, true is returned.- Specified by:
readBooleanin interfaceDataInput- Returns:
- the
booleanvalue read. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readByte
Reads a signedbytefrom the underlying input stream with value between -128 and 127- Specified by:
readBytein interfaceDataInput- Returns:
- the
bytevalue read. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readUnsignedByte
Reads an unsignedbytefrom the underlying input stream with value between 0 and 255- Specified by:
readUnsignedBytein interfaceDataInput- Returns:
- the
bytevalue read. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readShort
Reads a two byte signedshortfrom the underlying input stream in little endian order, low byte first.- Specified by:
readShortin interfaceDataInput- Returns:
- the
shortread. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readUnsignedShort
Reads a two byte unsignedshortfrom the underlying input stream in little endian order, low byte first.- Specified by:
readUnsignedShortin interfaceDataInput- Returns:
- the int value of the unsigned short read.
- Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readChar
Reads a two byte Unicodecharfrom the underlying input stream in little endian order, low byte first.- Specified by:
readCharin interfaceDataInput- Returns:
- the int value of the unsigned short read.
- Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readInt
Reads a four byte signedintfrom the underlying input stream in little endian order, low byte first.- Specified by:
readIntin interfaceDataInput- Returns:
- the
intread. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readLong
Reads an eight byte signedintfrom the underlying input stream in little endian order, low byte first.- Specified by:
readLongin interfaceDataInput- Returns:
- the
intread. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readUTF
Reads a string of no more than 65,535 characters from the underlying input stream using UTF-8 encoding. This method first reads a two byte short in big endian order as required by the UTF-8 specification. This gives the number of bytes in the UTF-8 encoded version of the string. Next this many bytes are read and decoded as UTF-8 encoded characters.- Specified by:
readUTFin interfaceDataInput- Returns:
- the decoded string
- Throws:
UTFDataFormatException- if the string cannot be decodedIOException- if the underlying stream throws an IOException.
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Returns:
- the next eight bytes of this input stream, interpreted as a
little endian
double. - Throws:
EOFException- if end of stream occurs before eight bytes have been read.IOException- if an I/O error occurs.
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Returns:
- the next four bytes of this input stream, interpreted as a
little endian
int. - Throws:
EOFException- if end of stream occurs before four bytes have been read.IOException- if an I/O error occurs.
-
skipBytes
See the general contract of theskipBytesmethod ofDataInput.Bytes for this operation are read from the contained input stream.
- Specified by:
skipBytesin interfaceDataInput- Parameters:
pLength- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- if an I/O error occurs.
-
readFully
See the general contract of thereadFullymethod ofDataInput.Bytes for this operation are read from the contained input stream.
- Specified by:
readFullyin interfaceDataInput- Parameters:
pBytes- the buffer into which the data is read.- Throws:
EOFException- if this input stream reaches the end before reading all the bytes.IOException- if an I/O error occurs.- See Also:
-
readFully
See the general contract of thereadFullymethod ofDataInput.Bytes for this operation are read from the contained input stream.
- Specified by:
readFullyin interfaceDataInput- Parameters:
pBytes- the buffer into which the data is read.pOffset- the start offset of the data.pLength- the number of bytes to read.- Throws:
EOFException- if this input stream reaches the end before reading all the bytes.IOException- if an I/O error occurs.- See Also:
-
readLine
Deprecated.This method does not properly convert bytes to characters.See the general contract of thereadLinemethod ofDataInput.Bytes for this operation are read 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.- See Also:
-