Class LittleEndianInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
net.simplace.core.io.endian.LittleEndianInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class LittleEndianInputStream extends FilterInputStream
Input stream that reads primitive values in little-endian byte order (counterpart of LittleEndianOutputStream).
  • Constructor Details

    • LittleEndianInputStream

      public LittleEndianInputStream(InputStream in)
      Parameters:
      in - the underlying stream
  • Method Details

    • readBoolean

      public boolean readBoolean() throws IOException
      Returns:
      true if the next byte is not 0
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • skipUntilETX

      public boolean skipUntilETX() throws IOException
      Skips all bytes up to and including the next ETX character.
      Returns:
      true if an ETX was found, false if the end of the stream was reached
      Throws:
      IOException - on read errors
    • readByte

      public byte readByte(int b) throws IOException
      Parameters:
      b - not used
      Returns:
      the next byte
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • readUnsignedByte

      public int readUnsignedByte() throws IOException
      Returns:
      the next byte as unsigned value (0..255)
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • readShort

      public short readShort() throws IOException
      Returns:
      the next 2 bytes as short (little-endian)
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • readUnsignedShort

      public int readUnsignedShort() throws IOException
      Returns:
      the next 2 bytes as unsigned short (little-endian)
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • readChar

      public char readChar() throws IOException
      Returns:
      the next 2 bytes as char (little-endian)
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • readInt

      public int readInt() throws IOException
      Returns:
      the next 4 bytes as int (little-endian)
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • readLong

      public long readLong() throws IOException
      Returns:
      the next 8 bytes as long (little-endian)
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • readUTF

      public String readUTF() throws IOException
      Reads a string in modified UTF-8 with a 2 byte length prefix (big-endian, as written by LittleEndianOutputStream.writeUTF(String)).
      Returns:
      the string
      Throws:
      IOException - at the end of the stream, for malformed data (UTFDataFormatException) or on read errors
    • readDouble

      public final double readDouble() throws IOException
      Returns:
      the next 8 bytes as double (little-endian)
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • readFloat

      public final float readFloat() throws IOException
      Returns:
      the next 4 bytes as float (little-endian)
      Throws:
      IOException - at the end of the stream (EOFException) or on read errors
    • skipBytes

      public final int skipBytes(int n) throws IOException
      Skips bytes; loops until all bytes are skipped.
      Parameters:
      n - number of bytes to skip
      Returns:
      n
      Throws:
      IOException - on read errors