Package com.tccc.kos.commons.util
Class ByteOrderInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.tccc.kos.commons.util.ByteOrderInputStream
- All Implemented Interfaces:
ByteOrderInput
,Closeable
,AutoCloseable
An input stream that reads objects in little or big endian format.
- Since:
- 1.0
- Version:
- 2022-08-31
-
Constructor Summary
ConstructorsConstructorDescriptionByteOrderInputStream
(ByteOrder endian, InputStream in) Create a wrapper around the specified input stream. -
Method Summary
Modifier and TypeMethodDescriptionReturn the inner input stream.int
read
(byte[] b) Read data into the byte array.int
read
(byte[] b, int off, int len) Read the specified number of bytes of data into the array starting at the specified offset.boolean
Read the next byte of input as a boolean value.byte
readByte()
Return the next available byte.Read a C string from input, terminated by a null byte.readCString
(int len) Read a C string from input, terminated by a null byte and padded up to the specified size.double
Read the next eight bytes as a double.Read a C string from input, terminated by a null byte and then process it for escaped UTF-8 characters.float
Read the next four bytes as a float.void
readFully
(byte[] b) Read data into the byte array and only return if the array is full or there is an EOF in the data.int
readInt()
Return the next four bytes as an int.long
readLong()
Return the next eight bytes as a long.short
Return the next two bytes as a signed short.Read all remaining input as a string.int
Return the next byte as an unsigned byte.int
Return the next two bytes as an unsigned short.int
skipBytes
(int n) Skip the specified number of bytes of input.Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ByteOrderInputStream
Create a wrapper around the specified input stream.- Parameters:
endian
- the endian of the streamin
- the specified input stream
-
-
Method Details
-
getInnerStream
Return the inner input stream.- Returns:
- the inner input stream this stream wraps
-
read
Description copied from interface:ByteOrderInput
Read data into the byte array. This is not guaranteed to fill the array.- Specified by:
read
in interfaceByteOrderInput
- Overrides:
read
in classFilterInputStream
- Parameters:
b
- the byte array to read into- Returns:
- the actual number of bytes read
- Throws:
IOException
-
read
Description copied from interface:ByteOrderInput
Read the specified number of bytes of data into the array starting at the specified offset.- Specified by:
read
in interfaceByteOrderInput
- Overrides:
read
in classFilterInputStream
- Parameters:
b
- the array to read data intooff
- the starting offsetlen
- the number of bytes to read- Returns:
- the actual number of bytes read
- Throws:
IOException
-
readFully
Description copied from interface:ByteOrderInput
Read data into the byte array and only return if the array is full or there is an EOF in the data.- Specified by:
readFully
in interfaceByteOrderInput
- Parameters:
b
- the array to read into- Throws:
IOException
- if there is an underlying exceptionEOFException
- if EOF is reached
-
skipBytes
Description copied from interface:ByteOrderInput
Skip the specified number of bytes of input. Returns the total number of bytes skipped.- Specified by:
skipBytes
in interfaceByteOrderInput
- Parameters:
n
- the number of bytes to skip- Returns:
- the number of byte skipped
- Throws:
IOException
- if there is an underlying exception
-
readBoolean
Description copied from interface:ByteOrderInput
Read the next byte of input as a boolean value.- Specified by:
readBoolean
in interfaceByteOrderInput
- Returns:
- the boolean value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readByte
Description copied from interface:ByteOrderInput
Return the next available byte.- Specified by:
readByte
in interfaceByteOrderInput
- Returns:
- the byte value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readUnsignedByte
Description copied from interface:ByteOrderInput
Return the next byte as an unsigned byte.- Specified by:
readUnsignedByte
in interfaceByteOrderInput
- Returns:
- the unsigned byte value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readShort
Description copied from interface:ByteOrderInput
Return the next two bytes as a signed short.- Specified by:
readShort
in interfaceByteOrderInput
- Returns:
- the short value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readUnsignedShort
Description copied from interface:ByteOrderInput
Return the next two bytes as an unsigned short.- Specified by:
readUnsignedShort
in interfaceByteOrderInput
- Returns:
- the unsigned short value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readInt
Description copied from interface:ByteOrderInput
Return the next four bytes as an int.- Specified by:
readInt
in interfaceByteOrderInput
- Returns:
- the int value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readLong
Description copied from interface:ByteOrderInput
Return the next eight bytes as a long.- Specified by:
readLong
in interfaceByteOrderInput
- Returns:
- the long value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readFloat
Description copied from interface:ByteOrderInput
Read the next four bytes as a float.- Specified by:
readFloat
in interfaceByteOrderInput
- Returns:
- the float value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readDouble
Description copied from interface:ByteOrderInput
Read the next eight bytes as a double.- Specified by:
readDouble
in interfaceByteOrderInput
- Returns:
- the double value
- Throws:
IOException
- if there is an underlying exception or EOF
-
readCString
Description copied from interface:ByteOrderInput
Read a C string from input, terminated by a null byte.- Specified by:
readCString
in interfaceByteOrderInput
- Returns:
- the C string converted to a string
- Throws:
IOException
- if there is an underlying exception or EOF
-
readEscapedCString
Description copied from interface:ByteOrderInput
Read a C string from input, terminated by a null byte and then process it for escaped UTF-8 characters.- Specified by:
readEscapedCString
in interfaceByteOrderInput
- Returns:
- the converted string
- Throws:
IOException
- if there is an underlying exception or EOF
-
readCString
Description copied from interface:ByteOrderInput
Read a C string from input, terminated by a null byte and padded up to the specified size.- Specified by:
readCString
in interfaceByteOrderInput
- Returns:
- the C string converted to a string
- Throws:
IOException
- if there is an underlying exception or EOF
-
readString
Description copied from interface:ByteOrderInput
Read all remaining input as a string. This assumes the data in the buffer is not null terminated as a normal C string.- Specified by:
readString
in interfaceByteOrderInput
- Returns:
- the remaining bytes converted to a string
- Throws:
IOException
- if there is an underlying exception or EOF
-