Package com.webcodepro.shrinkit.io
Class LittleEndianByteInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.webcodepro.shrinkit.io.LittleEndianByteInputStream
-
- All Implemented Interfaces:
ByteConstants
,java.io.Closeable
,java.lang.AutoCloseable
public class LittleEndianByteInputStream extends java.io.InputStream implements ByteConstants
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
Constructors Constructor Description LittleEndianByteInputStream(byte[] data)
Construct a LittleEndianByteInputStream from a byte array.LittleEndianByteInputStream(java.io.InputStream inputStream)
Construct a LittleEndianByteInputStream from an InputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getCrcValue()
Get the current CRC-16 value.long
getTotalBytesRead()
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.java.util.Date
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
seekFileType()
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 for
-
-
-
Constructor Detail
-
LittleEndianByteInputStream
public LittleEndianByteInputStream(java.io.InputStream inputStream)
Construct a LittleEndianByteInputStream from an InputStream.
-
LittleEndianByteInputStream
public LittleEndianByteInputStream(byte[] data)
Construct a LittleEndianByteInputStream from a byte array.
-
-
Method Detail
-
read
public int read() throws java.io.IOException
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 classjava.io.InputStream
- Throws:
java.io.IOException
-
readByte
public int readByte() throws java.io.IOException
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:
java.io.IOException
-
readBytes
public byte[] readBytes(int bytes) throws java.io.IOException
Get the next set of bytes as an array. If EOF encountered, an IOException is thrown.- Throws:
java.io.IOException
-
seekFileType
public int seekFileType() throws java.io.IOException
Test the beginning of the data stream for a magic signature, for up to a total of 2k bytes of leading garbage- Throws:
java.io.IOException
-
seekFileType
public int seekFileType(int max) throws java.io.IOException
Test the beginning of the data stream for a magic signature, specifying the maximum size of a signature to test for- Throws:
java.io.IOException
-
readWord
public int readWord() throws java.io.IOException
Read the two bytes in as a "Word" which needs to be stored as a Java int.- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException
Read the two bytes in as a "Long" which needs to be stored as a Java long.- Throws:
java.io.IOException
-
readDate
public java.util.Date readDate() throws java.io.IOException
Read the TimeRec into a Java Date object. Note that years 00-39 are assumed to be 2000-2039 per the NuFX addendum.- Throws:
java.io.IOException
- See Also:
- NuFX addendum
-
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.
-
-