Package com.luciad.io

Class TLcdDataInputStream

java.lang.Object
com.luciad.io.TLcdDataInputStream
All Implemented Interfaces:
DataInput, AutoCloseable

public class TLcdDataInputStream extends Object implements DataInput, AutoCloseable
This class is similar to a DataInputStream, except that it can also read little-endian binary data instead of only big-endian data.

The position is incremented before the read operations, so it will be incremented even if the operation fails.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    Position within a byte.
    protected DataInputStream
    Encapsulated DataInputStream object.
    protected boolean
    Specifies whether pairs of bytes in the data stream should be interpreted as little endian, i.e. with the least significant byte first.
    protected boolean
    Specifies whether pairs of words in the data stream should be interpreted as little endian, i.e. with the least significant word first.
    protected long
    Last marked valid position.
    protected long
    Position in the data stream.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a TLcdDataInputStream based on an InputStream.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Closes the data stream.
    final long
    Returns the position in the data stream.
    final boolean
    Returns true if the numbers read from the stream are interpreted in little endian format.
    final boolean
    Returns whether the words in the data stream are interpreted as little endian.
    void
    mark(int aReadLimit)
    Marks the current position in this input stream.
    boolean
    Tests if the data stream supports the mark and reset methods.
    final int
    read(byte[] aBuffer)
    Bytes for this operation are read from the contained input stream.
    final int
    read(byte[] aBuffer, int aOffset, int aLength)
    Bytes for this operation are read from the contained input stream.
    final double
    Reads a big-endian double.
    final float
    Reads a big-endian float.
    final int
    Reads a big-endian integer.
    final long
    Reads a big-endian long.
    final short
    Reads a big-endian short.
    final boolean
     
    final byte
    Reads a byte from the contained input stream.
    final char
    Reads a char in big or little endian mode.
    final double
    Reads an double in big or little endian mode.
    final float
    Reads an float in big or little endian mode.
    final void
    readFully(byte[] aBuffer)
    Bytes for this operation are read from the contained input stream.
    final void
    readFully(byte[] aBuffer, int aOffset, int aLength)
    Bytes for this operation are read from the contained input stream.
    final int
    Reads an integer in big or little endian mode.
    final int
    readInt(int aByteCount)
    Reads a little endian integer of the given number of bytes.
    final double
    Reads a little-endian double.
    final float
    Reads a little-endian float.
    final int
    Reads a little-endian integer.
    final long
    Reads a little-endian long.
    final String
    Deprecated.
    This method does not properly convert bytes to characters.
    final short
    Reads a little-endian short.
    final long
    Reads an long in big or little endian mode.
    final short
    Reads a short in big or little endian mode.
    final int
    Reads an unsigned byte from the contained input stream.
    final long
    Reads a unsigned int in big or little endian mode.
    final int
    Reads a unsigned short in big or little endian mode.
    final String
    Reads a Unicode string from the contained input stream.
    static String
    readUTF(DataInput aDataInput)
    Reads a Unicode character from the data stream.
    void
    Resets the data streams to its last marked valid position.
    final void
    Resets the position to 0.
    final void
    setLittleEndianMode(boolean aFlag)
    Specifies whether numbers read from the stream should be interpreted in little endian format.
    final void
    setLittleEndianWordMode(boolean aFlag)
    Specifies whether pairs of words in the data stream should be interpreted as little endian, i.e. with the least significant word first.
    final int
    skipBytes(int n)
    Bytes for this operation are read from the contained input stream.
    long
    skipBytes(long n)
    Attempts to skip over n bytes of data from the input stream, discarding the skipped bytes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fDataInputStream

      protected DataInputStream fDataInputStream
      Encapsulated DataInputStream object. All reads are redirected to this object.
    • fLittleEndianMode

      protected boolean fLittleEndianMode
      Specifies whether pairs of bytes in the data stream should be interpreted as little endian, i.e. with the least significant byte first. true on construction.
    • fLittleEndianWordMode

      protected boolean fLittleEndianWordMode
      Specifies whether pairs of words in the data stream should be interpreted as little endian, i.e. with the least significant word first. true on construction.
    • fPosition

      protected long fPosition
      Position in the data stream.
    • fMarkPosition

      protected long fMarkPosition
      Last marked valid position.
    • fBitPosition

      protected int fBitPosition
      Position within a byte.
  • Constructor Details

    • TLcdDataInputStream

      public TLcdDataInputStream(InputStream aInputStream)
      Constructs a TLcdDataInputStream based on an InputStream.
      Parameters:
      aInputStream - the InputStream to encapsulate.
  • Method Details

    • setLittleEndianMode

      public final void setLittleEndianMode(boolean aFlag)
      Specifies whether numbers read from the stream should be interpreted in little endian format. In little endian format, the data stream stores the least significant byte first (lowest address) and the most significant byte last (highest address). The default is true.
      Parameters:
      aFlag - true when numbers read from the stream should be interpreted in little endian format.
    • isLittleEndianMode

      public final boolean isLittleEndianMode()
      Returns true if the numbers read from the stream are interpreted in little endian format. In little endian format, the data stream stores the least significant byte first (lowest address) and the most significant byte last (highest address).
      Returns:
      true if the numbers read from the stream are interpreted in little endian format.
    • setLittleEndianWordMode

      public final void setLittleEndianWordMode(boolean aFlag)
      Specifies whether pairs of words in the data stream should be interpreted as little endian, i.e. with the least significant word first. In this context, a word refers to a pair of bytes. The pairs of bytes can be big endian or little endian, independently of this property. The default is true.
      Parameters:
      aFlag - whether to interpret the words in the data stream as little endian.
    • isLittleEndianWordMode

      public final boolean isLittleEndianWordMode()
      Returns whether the words in the data stream are interpreted as little endian.
      Returns:
      whether the words in the data stream are interpreted as little endian.
    • getPosition

      public final long getPosition()
      Returns the position in the data stream.
      Returns:
      the position in the data stream.
    • resetPosition

      public final void resetPosition()
      Resets the position to 0.
    • readShort

      public final short readShort() throws IOException
      Reads a short in big or little endian mode.
      Specified by:
      readShort in interface DataInput
      Returns:
      the short read.
      Throws:
      IOException - if an I/O error occurs.
    • readBIShort

      public final short readBIShort() throws IOException
      Reads a big-endian short.
      Returns:
      the short read.
      Throws:
      IOException - if an I/O error occurs.
    • readLIShort

      public final short readLIShort() throws IOException
      Reads a little-endian short.
      Returns:
      the short read.
      Throws:
      IOException - if an I/O error occurs.
    • readUnsignedShort

      public final int readUnsignedShort() throws IOException
      Reads a unsigned short in big or little endian mode.
      Specified by:
      readUnsignedShort in interface DataInput
      Returns:
      the unsigned short read.
      Throws:
      IOException - if an I/O error occurs.
    • readChar

      public final char readChar() throws IOException
      Reads a char in big or little endian mode.
      Specified by:
      readChar in interface DataInput
      Returns:
      the char read.
      Throws:
      IOException - if an I/O error occurs.
    • readInt

      public final int readInt() throws IOException
      Reads an integer in big or little endian mode.
      Specified by:
      readInt in interface DataInput
      Returns:
      the integer read.
      Throws:
      IOException - if an I/O error occurs.
    • readBIInt

      public final int readBIInt() throws IOException
      Reads a big-endian integer.
      Returns:
      the integer read.
      Throws:
      IOException - if an I/O error occurs.
    • readLIInt

      public final int readLIInt() throws IOException
      Reads a little-endian integer.
      Returns:
      the integer read.
      Throws:
      IOException - if an I/O error occurs.
    • readUnsignedInt

      public final long readUnsignedInt() throws IOException
      Reads a unsigned int in big or little endian mode.
      Returns:
      the unsigned int read.
      Throws:
      IOException - if an I/O error occurs.
    • readInt

      public final int readInt(int aByteCount) throws IOException
      Reads a little endian integer of the given number of bytes.
      Parameters:
      aByteCount - the number of bytes to read.
      Returns:
      the little endian integer read.
      Throws:
      IOException - if an I/O error occurs.
    • readLong

      public final long readLong() throws IOException
      Reads an long in big or little endian mode.
      Specified by:
      readLong in interface DataInput
      Returns:
      the long read.
      Throws:
      IOException - if an I/O error occurs.
    • readBILong

      public final long readBILong() throws IOException
      Reads a big-endian long.
      Returns:
      the long read.
      Throws:
      IOException - if an I/O error occurs.
    • readLILong

      public final long readLILong() throws IOException
      Reads a little-endian long.
      Returns:
      the long read.
      Throws:
      IOException - if an I/O error occurs.
    • readFloat

      public final float readFloat() throws IOException
      Reads an float in big or little endian mode.
      Specified by:
      readFloat in interface DataInput
      Returns:
      the float read.
      Throws:
      IOException - if an I/O error occurs.
    • readBIFloat

      public final float readBIFloat() throws IOException
      Reads a big-endian float.
      Returns:
      the float read.
      Throws:
      IOException - if an I/O error occurs.
    • readLIFloat

      public final float readLIFloat() throws IOException
      Reads a little-endian float.
      Returns:
      the float read.
      Throws:
      IOException - if an I/O error occurs.
    • readDouble

      public final double readDouble() throws IOException
      Reads an double in big or little endian mode.
      Specified by:
      readDouble in interface DataInput
      Returns:
      the double read.
      Throws:
      IOException - if an I/O error occurs.
    • readBIDouble

      public final double readBIDouble() throws IOException
      Reads a big-endian double.
      Returns:
      the double read.
      Throws:
      IOException - if an I/O error occurs.
    • readLIDouble

      public final double readLIDouble() throws IOException
      Reads a little-endian double.
      Returns:
      the double read.
      Throws:
      IOException - if an I/O error occurs.
    • read

      public final int read(byte[] aBuffer) throws IOException
      Bytes for this operation are read from the contained input stream. Calling this method is equivalent of calling read(aBuffer, 0, aBuffer.length);
      Parameters:
      aBuffer - the buffer into which the data is read.
      Returns:
      the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
      Throws:
      IOException - if an I/O error occurs.
    • read

      public final int read(byte[] aBuffer, int aOffset, int aLength) throws IOException
      Bytes for this operation are read from the contained input stream. There is no guarantee that aLength number of bytes are read, even when the contained input stream has enough data. Use readFully(byte[], int, int) for this.
      Parameters:
      aBuffer - the buffer into which the data is read.
      aOffset - the start offset of the data.
      aLength - the maximum number of bytes read.
      Returns:
      the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
      Throws:
      IOException - if an I/O error occurs.
    • readFully

      public final void readFully(byte[] aBuffer) throws IOException
      Bytes for this operation are read from the contained input stream.
      Specified by:
      readFully in interface DataInput
      Parameters:
      aBuffer - the buffer into which the data is read.
      Throws:
      IOException - if an I/O error occurs.
    • readFully

      public final void readFully(byte[] aBuffer, int aOffset, int aLength) throws IOException
      Bytes for this operation are read from the contained input stream.
      Specified by:
      readFully in interface DataInput
      Parameters:
      aBuffer - the buffer into which the data is read.
      aOffset - the start offset of the data.
      aLength - the number of bytes to read completely.
      Throws:
      IOException - if an I/O error occurs.
    • skipBytes

      public final int skipBytes(int n) throws IOException
      Bytes for this operation are read from the contained input stream.
      Specified by:
      skipBytes in interface DataInput
      Parameters:
      n - the number of bytes to be skipped.
      Returns:
      the actual number of bytes skipped.
      Throws:
      IOException - if an I/O error occurs.
    • readBoolean

      public final boolean readBoolean() throws IOException
      Specified by:
      readBoolean in interface DataInput
      Throws:
      IOException
    • readByte

      public final byte readByte() throws IOException
      Reads a byte from the contained input stream.
      Specified by:
      readByte in interface DataInput
      Returns:
      the byte value read.
      Throws:
      IOException - if an I/O error occurs.
    • readUnsignedByte

      public final int readUnsignedByte() throws IOException
      Reads an unsigned byte from the contained input stream.
      Specified by:
      readUnsignedByte in interface DataInput
      Returns:
      the unsigned byte value read.
      Throws:
      IOException - if an I/O error occurs.
    • readLine

      @Deprecated public final String readLine() throws IOException
      Deprecated.
      This method does not properly convert bytes to characters. See DataInputStream.readLine() for more information.
      Reads the next line from the contained input stream.
      Specified by:
      readLine in interface DataInput
      Returns:
      the next line of text from this input stream.
      Throws:
      IOException - if an I/O error occurs.
    • readUTF

      public final String readUTF() throws IOException
      Reads a Unicode string from the contained input stream.
      Specified by:
      readUTF in interface DataInput
      Returns:
      a Unicode string.
      Throws:
      IOException - if an I/O error occurs.
    • readUTF

      public static String readUTF(DataInput aDataInput) throws IOException
      Reads a Unicode character from the data stream.
      Parameters:
      aDataInput - a data input stream.
      Returns:
      a Unicode string.
      Throws:
      IOException - if an I/O error occurs.
    • markSupported

      public boolean markSupported()
      Tests if the data stream supports the mark and reset methods.
      Returns:
      true if the data stream type supports the mark and reset method; false otherwise.
    • mark

      public void mark(int aReadLimit)
      Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

      The aReadLimit argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

      Parameters:
      aReadLimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
    • reset

      public void reset() throws IOException
      Resets the data streams to its last marked valid position.
      Throws:
      IOException - if an I/O error occurs.
    • skipBytes

      public long skipBytes(long n) throws IOException
      Attempts to skip over n bytes of data from the input stream, discarding the skipped bytes. This method never throws an EOFException. The actual number of bytes skipped is returned.
      Parameters:
      n - the number of bytes to be skipped. Must be positive because the input stream might not support going back.
      Returns:
      the actual number of bytes skipped.
      Throws:
      IOException
      Since:
      2018.0
    • close

      public final void close() throws IOException
      Closes the data stream.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - if an I/O error occurs.