Package com.webcodepro.shrinkit.io
Class LittleEndianByteInputStream
java.lang.Object
java.io.InputStream
com.webcodepro.shrinkit.io.LittleEndianByteInputStream
- All Implemented Interfaces:
ByteConstants
,Closeable
,AutoCloseable
A simple class to hide the source of byte data.
-
Field Summary
Fields inherited from interface com.webcodepro.shrinkit.io.ByteConstants
BXY_ID, NUFILE_ID, NUFX_ID, TIMEREC_DAY, TIMEREC_HOUR, TIMEREC_LENGTH, TIMEREC_MINUTE, TIMEREC_MONTH, TIMEREC_NULL, TIMEREC_SECOND, TIMEREC_WEEKDAY, TIMEREC_YEAR
-
Constructor Summary
ConstructorsConstructorDescriptionLittleEndianByteInputStream
(byte[] data) Construct a LittleEndianByteInputStream from a byte array.LittleEndianByteInputStream
(InputStream inputStream) Construct a LittleEndianByteInputStream from an InputStream. -
Method Summary
Modifier and TypeMethodDescriptionlong
Get the current CRC-16 value.long
Answer with the total number of bytes read.int
read()
Get the next byte.int
readByte()
Get the next byte and fail if we are at EOF.byte[]
readBytes
(int bytes) Get the next set of bytes as an array.readDate()
Read the TimeRec into a Java Date object.long
readLong()
Read the two bytes in as a "Long" which needs to be stored as a Java long.int
readWord()
Read the two bytes in as a "Word" which needs to be stored as a Java int.void
resetCrc()
Reset the CRC-16 to $0000.int
Test the beginning of the data stream for a magic signature, for up to a total of 2k bytes of leading garbageint
seekFileType
(int max) Test the beginning of the data stream for a magic signature, specifying the maximum size of a signature to test forMethods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
LittleEndianByteInputStream
Construct a LittleEndianByteInputStream from an InputStream. -
LittleEndianByteInputStream
public LittleEndianByteInputStream(byte[] data) Construct a LittleEndianByteInputStream from a byte array.
-
-
Method Details
-
read
Get the next byte. Returns -1 if at end of input. Note that an unsigned byte needs to be returned in a larger container (ie, a short or int or long).- Specified by:
read
in classInputStream
- Throws:
IOException
-
readByte
Get the next byte and fail if we are at EOF. Note that an unsigned byte needs to be returned in a larger container (ie, a short or int or long).- Throws:
IOException
-
readBytes
Get the next set of bytes as an array. If EOF encountered, an IOException is thrown.- Throws:
IOException
-
seekFileType
Test the beginning of the data stream for a magic signature, for up to a total of 2k bytes of leading garbage- Throws:
IOException
-
seekFileType
Test the beginning of the data stream for a magic signature, specifying the maximum size of a signature to test for- Throws:
IOException
-
readWord
Read the two bytes in as a "Word" which needs to be stored as a Java int.- Throws:
IOException
-
readLong
Read the two bytes in as a "Long" which needs to be stored as a Java long.- Throws:
IOException
-
readDate
Read the TimeRec into a Java Date object. Note that years 00-39 are assumed to be 2000-2039 per the NuFX addendum.- Throws:
IOException
- See Also:
-
resetCrc
public void resetCrc()Reset the CRC-16 to $0000. -
getCrcValue
public long getCrcValue()Get the current CRC-16 value. -
getTotalBytesRead
public long getTotalBytesRead()Answer with the total number of bytes read.
-