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 TypeMethodDescriptionintReturn the inner input stream.intread(byte[] b) Read data into the byte array.intread(byte[] b, int off, int len) Read the specified number of bytes of data into the array starting at the specified offset.booleanRead the next byte of input as a boolean value.bytereadByte()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.doubleRead 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.floatRead the next four bytes as a float.voidreadFully(byte[] b) Read data into the byte array and only return if the array is full or there is an EOF in the data.intreadInt()Return the next four bytes as an int.longreadLong()Return the next eight bytes as a long.shortReturn the next two bytes as a signed short.Read all remaining input as a string.intReturn the next byte as an unsigned byte.intReturn the next two bytes as an unsigned short.intskipBytes(int n) Skip the specified number of bytes of input.Methods inherited from class java.io.FilterInputStream
close, mark, markSupported, read, reset, skipMethods 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
-
available
public int available()- Overrides:
availablein classFilterInputStream
-
read
Description copied from interface:ByteOrderInputRead data into the byte array. This is not guaranteed to fill the array.- Specified by:
readin interfaceByteOrderInput- Overrides:
readin classFilterInputStream- Parameters:
b- the byte array to read into- Returns:
- the actual number of bytes read
- Throws:
IOException
-
read
Description copied from interface:ByteOrderInputRead the specified number of bytes of data into the array starting at the specified offset.- Specified by:
readin interfaceByteOrderInput- Overrides:
readin 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:ByteOrderInputRead data into the byte array and only return if the array is full or there is an EOF in the data.- Specified by:
readFullyin 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:ByteOrderInputSkip the specified number of bytes of input. Returns the total number of bytes skipped.- Specified by:
skipBytesin 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:ByteOrderInputRead the next byte of input as a boolean value.- Specified by:
readBooleanin interfaceByteOrderInput- Returns:
- the boolean value
- Throws:
IOException- if there is an underlying exception or EOF
-
readByte
Description copied from interface:ByteOrderInputReturn the next available byte.- Specified by:
readBytein interfaceByteOrderInput- Returns:
- the byte value
- Throws:
IOException- if there is an underlying exception or EOF
-
readUnsignedByte
Description copied from interface:ByteOrderInputReturn the next byte as an unsigned byte.- Specified by:
readUnsignedBytein interfaceByteOrderInput- Returns:
- the unsigned byte value
- Throws:
IOException- if there is an underlying exception or EOF
-
readShort
Description copied from interface:ByteOrderInputReturn the next two bytes as a signed short.- Specified by:
readShortin interfaceByteOrderInput- Returns:
- the short value
- Throws:
IOException- if there is an underlying exception or EOF
-
readUnsignedShort
Description copied from interface:ByteOrderInputReturn the next two bytes as an unsigned short.- Specified by:
readUnsignedShortin interfaceByteOrderInput- Returns:
- the unsigned short value
- Throws:
IOException- if there is an underlying exception or EOF
-
readInt
Description copied from interface:ByteOrderInputReturn the next four bytes as an int.- Specified by:
readIntin interfaceByteOrderInput- Returns:
- the int value
- Throws:
IOException- if there is an underlying exception or EOF
-
readLong
Description copied from interface:ByteOrderInputReturn the next eight bytes as a long.- Specified by:
readLongin interfaceByteOrderInput- Returns:
- the long value
- Throws:
IOException- if there is an underlying exception or EOF
-
readFloat
Description copied from interface:ByteOrderInputRead the next four bytes as a float.- Specified by:
readFloatin interfaceByteOrderInput- Returns:
- the float value
- Throws:
IOException- if there is an underlying exception or EOF
-
readDouble
Description copied from interface:ByteOrderInputRead the next eight bytes as a double.- Specified by:
readDoublein interfaceByteOrderInput- Returns:
- the double value
- Throws:
IOException- if there is an underlying exception or EOF
-
readCString
Description copied from interface:ByteOrderInputRead a C string from input, terminated by a null byte.- Specified by:
readCStringin interfaceByteOrderInput- Returns:
- the C string converted to a string
- Throws:
IOException- if there is an underlying exception or EOF
-
readEscapedCString
Description copied from interface:ByteOrderInputRead a C string from input, terminated by a null byte and then process it for escaped UTF-8 characters.- Specified by:
readEscapedCStringin interfaceByteOrderInput- Returns:
- the converted string
- Throws:
IOException- if there is an underlying exception or EOF
-
readCString
Description copied from interface:ByteOrderInputRead a C string from input, terminated by a null byte and padded up to the specified size.- Specified by:
readCStringin interfaceByteOrderInput- Returns:
- the C string converted to a string
- Throws:
IOException- if there is an underlying exception or EOF
-
readString
Description copied from interface:ByteOrderInputRead all remaining input as a string. This assumes the data in the buffer is not null terminated as a normal C string.- Specified by:
readStringin interfaceByteOrderInput- Returns:
- the remaining bytes converted to a string
- Throws:
IOException- if there is an underlying exception or EOF
-