SwappedDataInputStream (Commons IO 2.5)
Date: 2016-12-01

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:
    java.io.Closeable, java.io.DataInput, java.lang.AutoCloseable

      public class SwappedDataInputStream
      extends ProxyInputStream
      implements java.io.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.

  Origin of code: Avalon Excalibur (IO)

  Version:
    CVS $Revision: 1302050 $

- - ### Field Summary

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

      `in`

  - ### Constructor Summary

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

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `readBoolean()` Return ``readByte()` != 0`
    `byte` | `readByte()` Invokes the delegate's `read()` method.
    `char` | `readChar()` Reads a character delegating to `readShort()`.
    `double` | `readDouble()` Delegates to `EndianUtils.readSwappedDouble(InputStream)`.
    `float` | `readFloat()` Delegates to `EndianUtils.readSwappedFloat(InputStream)`.
    `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()` Delegates to `EndianUtils.readSwappedInteger(InputStream)`.
    `java.lang.String` | `readLine()` Not currently supported - throws `UnsupportedOperationException`.
    `long` | `readLong()` Delegates to `EndianUtils.readSwappedLong(InputStream)`.
    `short` | `readShort()` Delegates to `EndianUtils.readSwappedShort(InputStream)`.
    `int` | `readUnsignedByte()` Invokes the delegate's `read()` method.
    `int` | `readUnsignedShort()` Delegates to `EndianUtils.readSwappedUnsignedShort(InputStream)`.
    `java.lang.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, skip`

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

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

- - ### Constructor Detail

    - #### SwappedDataInputStream

          public SwappedDataInputStream(java.io.InputStream input)

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

  - ### Method Detail

    - #### readBoolean

          public boolean readBoolean()
                              throws java.io.IOException,
                                     java.io.EOFException

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

    - #### readByte

          public byte readByte()
                        throws java.io.IOException,
                               java.io.EOFException

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

    - #### readChar

          public char readChar()
                        throws java.io.IOException,
                               java.io.EOFException

      Reads a character delegating to `readShort()`.
      Specified by:
        `readChar` in interface `java.io.DataInput`
      Returns:
        the byte read or -1 if the end of stream
      Throws:
        `java.io.IOException` - if an I/O error occurs
        `java.io.EOFException` - if an end of file is reached unexpectedly

    - #### readDouble

          public double readDouble()
                            throws java.io.IOException,
                                   java.io.EOFException

      Delegates to `EndianUtils.readSwappedDouble(InputStream)`.
      Specified by:
        `readDouble` in interface `java.io.DataInput`
      Returns:
        the read long
      Throws:
        `java.io.IOException` - if an I/O error occurs
        `java.io.EOFException` - if an end of file is reached unexpectedly

    - #### readFloat

          public float readFloat()
                          throws java.io.IOException,
                                 java.io.EOFException

      Delegates to `EndianUtils.readSwappedFloat(InputStream)`.
      Specified by:
        `readFloat` in interface `java.io.DataInput`
      Returns:
        the read long
      Throws:
        `java.io.IOException` - if an I/O error occurs
        `java.io.EOFException` - if an end of file is reached unexpectedly

    - #### readFully

          public void readFully(byte[] data)
                         throws java.io.IOException,
                                java.io.EOFException

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

    - #### readFully

          public void readFully(byte[] data,
                       int offset,
                       int length)
                         throws java.io.IOException,
                                java.io.EOFException

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

    - #### readInt

          public int readInt()
                      throws java.io.IOException,
                             java.io.EOFException

      Delegates to `EndianUtils.readSwappedInteger(InputStream)`.
      Specified by:
        `readInt` in interface `java.io.DataInput`
      Returns:
        the read long
      Throws:
        `java.io.EOFException` - if an end of file is reached unexpectedly
        `java.io.IOException` - if an I/O error occurs

    - #### readLine

          public java.lang.String readLine()
                                    throws java.io.IOException,
                                           java.io.EOFException

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

    - #### readLong

          public long readLong()
                        throws java.io.IOException,
                               java.io.EOFException

      Delegates to `EndianUtils.readSwappedLong(InputStream)`.
      Specified by:
        `readLong` in interface `java.io.DataInput`
      Returns:
        the read long
      Throws:
        `java.io.EOFException` - if an end of file is reached unexpectedly
        `java.io.IOException` - if an I/O error occurs

    - #### readShort

          public short readShort()
                          throws java.io.IOException,
                                 java.io.EOFException

      Delegates to `EndianUtils.readSwappedShort(InputStream)`.
      Specified by:
        `readShort` in interface `java.io.DataInput`
      Returns:
        the read long
      Throws:
        `java.io.EOFException` - if an end of file is reached unexpectedly
        `java.io.IOException` - if an I/O error occurs

    - #### readUnsignedByte

          public int readUnsignedByte()
                               throws java.io.IOException,
                                      java.io.EOFException

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

    - #### readUnsignedShort

          public int readUnsignedShort()
                                throws java.io.IOException,
                                       java.io.EOFException

      Delegates to `EndianUtils.readSwappedUnsignedShort(InputStream)`.
      Specified by:
        `readUnsignedShort` in interface `java.io.DataInput`
      Returns:
        the read long
      Throws:
        `java.io.EOFException` - if an end of file is reached unexpectedly
        `java.io.IOException` - if an I/O error occurs

    - #### readUTF

          public java.lang.String readUTF()
                                   throws java.io.IOException,
                                          java.io.EOFException

      Not currently supported - throws `UnsupportedOperationException`.
      Specified by:
        `readUTF` in interface `java.io.DataInput`
      Returns:
        UTF String read
      Throws:
        `java.io.EOFException` - if an end of file is reached unexpectedly
        `java.io.IOException` - if an I/O error occurs

    - #### skipBytes

          public int skipBytes(int count)
                        throws java.io.IOException,
                               java.io.EOFException

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

Copyright (c) 2002-2016 Apache Software Foundation