Package org.apache.commons.io.input

# Class SwappedDataInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.io.input.ProxyInputStream
org.apache.commons.io.input.SwappedDataInputStream

All Implemented Interfaces:
  `Closeable`, `DataInput`, `AutoCloseable`

public class SwappedDataInputStream extends ProxyInputStream implements DataInput
DataInput for systems relying on little-endian data formats. When read, values will be changed from little-endian to big-endian formats for internal usage.

Provenance: Avalon Excalibur (IO)

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.commons.io.input.ProxyInputStream

  `ProxyInputStream.AbstractBuilder<T,B extends AbstractStreamBuilder<T,B>>`

- ## Field Summary

  ### Fields inherited from class java.io.FilterInputStream

  `in`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SwappedDataInputStream(InputStream input)`
  Constructs a SwappedDataInputStream.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `readBoolean()`
  Return ``readByte()` !`
  `byte`
  `readByte()`
  Invokes the delegate's `read()` method.
  `char`
  `readChar()`
  Reads a 2 byte, unsigned, little endian UTF-16 code point.
  `double`
  `readDouble()`
  Reads an 8 byte, two's complement, little-endian long.
  `float`
  `readFloat()`
  Reads a 4 byte, IEEE 754, little-endian float.
  `void`
  `readFully(byte[] data)`
  Invokes the delegate's `read(byte[] data, int, int)` method.
  `void`
  `readFully(byte[] data, int offset, int length)`
  Invokes the delegate's `read(byte[] data, int, int)` method.
  `int`
  `readInt()`
  Reads a 4 byte, two's complement little-endian integer.
  `String`
  `readLine()`
  Not currently supported - throws `UnsupportedOperationException`.
  `long`
  `readLong()`
  Reads an 8 byte, two's complement little-endian integer.
  `short`
  `readShort()`
  Reads a 2 byte, two's complement, little-endian integer.
  `int`
  `readUnsignedByte()`
  Invokes the delegate's `read()` method.
  `int`
  `readUnsignedShort()`
  Reads a 2 byte, unsigned, little-endian integer.
  `String`
  `readUTF()`
  Not currently supported - throws `UnsupportedOperationException`.
  `int`
  `skipBytes(int count)`
  Invokes the delegate's `skip(int)` method.

  ### Methods inherited from class org.apache.commons.io.input.ProxyInputStream

  `afterRead, available, beforeRead, close, handleIOException, mark, markSupported, read, read, read, reset, setReference, skip, unwrap`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SwappedDataInputStream

    public SwappedDataInputStream(InputStream input)
    Constructs a SwappedDataInputStream.
    Parameters:
      `input` - InputStream to read from

- ## Method Details

  - ### readBoolean

    public boolean readBoolean() throws IOException, EOFException
    Return ``readByte()` != 0`
    Specified by:
      `readBoolean` in interface `DataInput`
    Returns:
      false if the byte read is zero, otherwise true
    Throws:
      `IOException` - if an I/O error occurs.
      `EOFException` - if an end of file is reached unexpectedly

  - ### readByte

    public byte readByte() throws IOException, EOFException
    Invokes the delegate's `read()` method.
    Specified by:
      `readByte` in interface `DataInput`
    Returns:
      the byte read or -1 if the end of stream
    Throws:
      `IOException` - if an I/O error occurs.
      `EOFException` - if an end of file is reached unexpectedly

  - ### readChar

    public char readChar() throws IOException, EOFException
    Reads a 2 byte, unsigned, little endian UTF-16 code point.
    Specified by:
      `readChar` in interface `DataInput`
    Returns:
      the UTF-16 code point read or -1 if the end of stream
    Throws:
      `IOException` - if an I/O error occurs.
      `EOFException` - if an end of file is reached unexpectedly

  - ### readDouble

    public double readDouble() throws IOException, EOFException
    Reads an 8 byte, two's complement, little-endian long.
    Specified by:
      `readDouble` in interface `DataInput`
    Returns:
      the read long
    Throws:
      `IOException` - if an I/O error occurs.
      `EOFException` - if an end of file is reached unexpectedly

  - ### readFloat

    public float readFloat() throws IOException, EOFException
    Reads a 4 byte, IEEE 754, little-endian float.
    Specified by:
      `readFloat` in interface `DataInput`
    Returns:
      the read float
    Throws:
      `IOException` - if an I/O error occurs.
      `EOFException` - if an end of file is reached unexpectedly

  - ### readFully

    public void readFully(byte[] data) throws IOException, EOFException
    Invokes the delegate's `read(byte[] data, int, int)` method.
    Specified by:
      `readFully` in interface `DataInput`
    Parameters:
      `data` - the buffer to read the bytes into
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs.

  - ### readFully

    public void readFully(byte[] data, int offset, int length) throws IOException, EOFException
    Invokes the delegate's `read(byte[] data, int, int)` method.
    Specified by:
      `readFully` in interface `DataInput`
    Parameters:
      `data` - the buffer to read the bytes into
      `offset` - The start offset
      `length` - The number of bytes to read
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs.

  - ### readInt

    public int readInt() throws IOException, EOFException
    Reads a 4 byte, two's complement little-endian integer.
    Specified by:
      `readInt` in interface `DataInput`
    Returns:
      the read int
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs.

  - ### readLine

    public String readLine() throws IOException, EOFException
    Not currently supported - throws `UnsupportedOperationException`.
    Specified by:
      `readLine` in interface `DataInput`
    Returns:
      the line read
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs
      `UnsupportedOperationException` - always

  - ### readLong

    public long readLong() throws IOException, EOFException
    Reads an 8 byte, two's complement little-endian integer.
    Specified by:
      `readLong` in interface `DataInput`
    Returns:
      the read long
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs.

  - ### readShort

    public short readShort() throws IOException, EOFException
    Reads a 2 byte, two's complement, little-endian integer.
    Specified by:
      `readShort` in interface `DataInput`
    Returns:
      the read short
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs.

  - ### readUnsignedByte

    public int readUnsignedByte() throws IOException, EOFException
    Invokes the delegate's `read()` method.
    Specified by:
      `readUnsignedByte` in interface `DataInput`
    Returns:
      the byte read or -1 if the end of stream
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs.

  - ### readUnsignedShort

    public int readUnsignedShort() throws IOException, EOFException
    Reads a 2 byte, unsigned, little-endian integer.
    Specified by:
      `readUnsignedShort` in interface `DataInput`
    Returns:
      the read short
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs.

  - ### readUTF

    public String readUTF() throws IOException, EOFException
    Not currently supported - throws `UnsupportedOperationException`.
    Specified by:
      `readUTF` in interface `DataInput`
    Returns:
      never
    Throws:
      `EOFException` - if an end of file is reached unexpectedly
      `IOException` - if an I/O error occurs
      `UnsupportedOperationException` - always

  - ### skipBytes

    public int skipBytes(int count) throws IOException
    Invokes the delegate's `skip(int)` method.
    Specified by:
      `skipBytes` in interface `DataInput`
    Parameters:
      `count` - the number of bytes to skip
    Returns:
      the number of bytes skipped or -1 if the end of stream
    Throws:
      `IOException` - if an I/O error occurs