Class 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.
    • 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 garbage
      int seekFileType​(int max)
      Test the beginning of the data stream for a magic signature, specifying the maximum size of a signature to test for
      • Methods inherited from class java.io.InputStream

        available, close, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 class java.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.