Package com.aurumsmods.littlebigio
Class BinaryInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.aurumsmods.littlebigio.BinaryInputStream
- All Implemented Interfaces:
ByteOrdered
,UnsignedIntInput
,Closeable
,DataInput
,AutoCloseable
public class BinaryInputStream
extends FilterInputStream
implements DataInput, ByteOrdered, UnsignedIntInput
A binary input stream provides readability of primitive data types from an
underlying input stream. The order in which the bytes are interpreted can be
either little endian or big endian (see
ByteOrder
).
This implements DataInput
but intentionally violates the
specifications prescribed by the contract. This is because DataInput
explicitly states the implementation of big-endian byte ordering.
BinaryInputStream
is not necessarily thread-safe due to it using a
buffer to read multiple bytes at once.
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorDescriptionCreates a newBinaryInputStream
that uses the given underlyingInputStream
.BinaryInputStream
(InputStream in, ByteOrder byteOrder) Creates a newBinaryInputStream
that uses the given underlyingInputStream
. -
Method Summary
Modifier and TypeMethodDescriptiongetOrder()
Returns theByteOrder
.boolean
Reads one input byte from the input stream. and returnstrue
if that byte is nonzero,false
if that byte is zero.byte
readByte()
Reads and returns one signedbyte
from the input stream.char
readChar()
Reads two bytes from the input stream and returns thechar
value converted from these bytes.double
Reads eight bytes from the input stream and returns thedouble
value converted from these bytes.float
Reads four bytes from the input stream and returns thefloat
value converted from these bytes.void
readFully
(byte[] b) Reads some bytes from the input stream into the given byte array.void
readFully
(byte[] b, int off, int len) Reads the specified number of bytes from the input stream into the given byte array.int
readInt()
Reads four bytes from the input stream and returns the signedint
value converted from these bytes.readLine()
Deprecated.long
readLong()
Reads eight bytes from the input stream and returns the signedlong
value converted from these bytes.short
Reads two bytes from the input stream and returns the signedshort
value converted from these bytes.int
Reads and returns one unsignedbyte
from the input stream.long
Reads four bytes from the input stream and returns the unsignedint
value converted from these bytes.int
Reads two bytes from the input stream and returns the unsignedshort
value converted from these bytes.readUTF()
Reads and returns a Unicode character string encoded in modified UTF-8 format from the input stream.void
Sets theByteOrder
to the specified value.int
skipBytes
(int n) Skips over and discards exactlyn
bytes of data from this input stream.Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, read, reset, skip
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.aurumsmods.littlebigio.ByteOrdered
isBigEndian, isLittleEndian, isNativeOrder, swapOrder
-
Constructor Details
-
BinaryInputStream
Creates a newBinaryInputStream
that uses the given underlyingInputStream
. The system's native byte order will be used when reading data.- Parameters:
in
- theInputStream
to read from.- See Also:
-
BinaryInputStream
Creates a newBinaryInputStream
that uses the given underlyingInputStream
. The specified byte order will be used when reading data.- Parameters:
in
- theInputStream
to read from.byteOrder
- theByteOrder
that specifies how to read data.- Throws:
NullPointerException
- ifbyteOrder
isnull
.
-
-
Method Details
-
getOrder
Returns theByteOrder
.- Specified by:
getOrder
in interfaceByteOrdered
- Returns:
- the
ByteOrder
.
-
setOrder
- Specified by:
setOrder
in interfaceByteOrdered
- Parameters:
byteOrder
- theByteOrder
.- Throws:
NullPointerException
- ifbyteOrder
isnull
.
-
readFully
Reads some bytes from the input stream into the given byte array. The number of bytes read is equal to the length of b. This method blocks untillen
bytes of input data have been read, end of stream is detected, or an exception is thrown. This does not close the stream.- Specified by:
readFully
in interfaceDataInput
- Parameters:
b
- the byte array into which the data is read.- Throws:
NullPointerException
- ifb
isnull
.IOException
- if an I/O error occurs.EOFException
- if the input stream reaches the end before reading all bytes.- See Also:
-
readFully
Reads the specified number of bytes from the input stream into the given byte array. This method blocks untillen
bytes of input data have been read, end of stream is detected, or an exception is thrown. This does not close the stream.- Specified by:
readFully
in interfaceDataInput
- Parameters:
b
- the byte array into which the data is read.off
- the offset inb
at which the data is written.len
- the maximum number of bytes to read.- Throws:
NullPointerException
- ifb
isnull
.IndexOutOfBoundsException
- ifoff
is negative,len
is negative, orlen
is greater thanb.length - off
.IOException
- if an I/O error occurs.EOFException
- if the input stream reaches the end before reading all bytes.- See Also:
-
skipBytes
Skips over and discards exactlyn
bytes of data from this input stream. Ifn
is zero or negative, then no bytes are skipped. This method blocks untiln
bytes have been skipped, end of stream is detected, or an exception is thrown.- Specified by:
skipBytes
in interfaceDataInput
- Parameters:
n
- the number of bytes to skip.- Returns:
- the number of bytes that were skipped.
- Throws:
IOException
- if an I/O error occurs.
-
readBoolean
Reads one input byte from the input stream. and returnstrue
if that byte is nonzero,false
if that byte is zero.- Specified by:
readBoolean
in interfaceDataInput
- Returns:
- the
boolean
value read. - Throws:
EOFException
- if this stream reached the end before reading the byte.IOException
- if an I/O error occurs.
-
readByte
Reads and returns one signedbyte
from the input stream.- Specified by:
readByte
in interfaceDataInput
- Returns:
- the signed
byte
value read. - Throws:
EOFException
- if this stream reached the end before reading the byte.IOException
- if an I/O error occurs.
-
readUnsignedByte
Reads and returns one unsignedbyte
from the input stream.- Specified by:
readUnsignedByte
in interfaceDataInput
- Returns:
- the unsigned
byte
value read. - Throws:
EOFException
- if this stream reached the end before reading the byte.IOException
- if an I/O error occurs.
-
readShort
Reads two bytes from the input stream and returns the signedshort
value converted from these bytes.- Specified by:
readShort
in interfaceDataInput
- Returns:
- the signed
short
value read. - Throws:
EOFException
- if this stream reached the end before reading all the bytes.IOException
- if an I/O error occurs.- See Also:
-
readUnsignedShort
Reads two bytes from the input stream and returns the unsignedshort
value converted from these bytes.- Specified by:
readUnsignedShort
in interfaceDataInput
- Returns:
- the unsigned
short
value read. - Throws:
EOFException
- if this stream reached the end before reading all the bytes.IOException
- if an I/O error occurs.- See Also:
-
readChar
Reads two bytes from the input stream and returns thechar
value converted from these bytes.- Specified by:
readChar
in interfaceDataInput
- Returns:
- the
char
value read. - Throws:
EOFException
- if this stream reached the end before reading all the bytes.IOException
- if an I/O error occurs.
-
readInt
Reads four bytes from the input stream and returns the signedint
value converted from these bytes.- Specified by:
readInt
in interfaceDataInput
- Returns:
- the signed
int
value read. - Throws:
EOFException
- if this stream reached the end before reading all the bytes.IOException
- if an I/O error occurs.- See Also:
-
readUnsignedInt
Reads four bytes from the input stream and returns the unsignedint
value converted from these bytes.- Specified by:
readUnsignedInt
in interfaceUnsignedIntInput
- Returns:
- the unsigned
int
value read. - Throws:
EOFException
- if this stream reached the end before reading all the bytes.IOException
- if an I/O error occurs.- See Also:
-
readLong
Reads eight bytes from the input stream and returns the signedlong
value converted from these bytes.- Specified by:
readLong
in interfaceDataInput
- Returns:
- the signed
long
value read. - Throws:
EOFException
- if this stream reached the end before reading all the bytes.IOException
- if an I/O error occurs.- See Also:
-
readFloat
Reads four bytes from the input stream and returns thefloat
value converted from these bytes.- Specified by:
readFloat
in interfaceDataInput
- Returns:
- the
float
value read. - Throws:
EOFException
- if this stream reached the end before reading all the bytes.IOException
- if an I/O error occurs.- See Also:
-
readDouble
Reads eight bytes from the input stream and returns thedouble
value converted from these bytes.- Specified by:
readDouble
in interfaceDataInput
- Returns:
- the
double
value read. - Throws:
EOFException
- if this stream reached the end before reading all the bytes.IOException
- if an I/O error occurs.- See Also:
-
readLine
Deprecated.UseBufferedReader.readLine()
instead.Not implemented: useBufferedReader
instead. This function always throws aUnsupportedOperationException
when invoked.- Specified by:
readLine
in interfaceDataInput
- Returns:
- n/a
- Throws:
IOException
- n/aUnsupportedOperationException
- always thrown.
-
readUTF
Reads and returns a Unicode character string encoded in modified UTF-8 format from the input stream. This callsDataInputStream.readUTF(DataInput)
. See the class documentation forDataInput
for details on the modified UTF-8 format.- Specified by:
readUTF
in interfaceDataInput
- Returns:
- the Unicode string read.
- Throws:
IOException
- if an I/O error occurs.
-
BufferedReader.readLine()
instead.