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.Origin of code: Avalon Excalibur (IO)
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in
Constructor Summary
Constructors Constructor and Description SwappedDataInputStream(InputStream input)
Constructs a SwappedDataInputStream.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean
readBoolean()
ReturnreadByte()
!= 0byte
readByte()
Invokes the delegate'sread()
method.char
readChar()
Reads a character delegating toreadShort()
.double
readDouble()
Delegates toEndianUtils.readSwappedDouble(InputStream)
.float
readFloat()
Delegates toEndianUtils.readSwappedFloat(InputStream)
.void
readFully(byte[] data)
Invokes the delegate'sread(byte[] data, int, int)
method.void
readFully(byte[] data, int offset, int length)
Invokes the delegate'sread(byte[] data, int, int)
method.int
readInt()
Delegates toEndianUtils.readSwappedInteger(InputStream)
.String
readLine()
Not currently supported - throwsUnsupportedOperationException
.long
readLong()
Delegates toEndianUtils.readSwappedLong(InputStream)
.short
readShort()
Delegates toEndianUtils.readSwappedShort(InputStream)
.int
readUnsignedByte()
Invokes the delegate'sread()
method.int
readUnsignedShort()
Delegates toEndianUtils.readSwappedUnsignedShort(InputStream)
.String
readUTF()
Not currently supported - throwsUnsupportedOperationException
.int
skipBytes(int count)
Invokes the delegate'sskip(int)
method.Methods inherited from class org.apache.commons.io.input.ProxyInputStream
afterRead, available, beforeRead, close, handleIOException, mark, markSupported, read, read, read, reset, skip
-
Constructor Detail
SwappedDataInputStream
public SwappedDataInputStream(InputStream input)
Constructs a SwappedDataInputStream.- Parameters:
-
input
- InputStream to read from
Method Detail
readBoolean
public boolean readBoolean() throws IOException, EOFException
ReturnreadByte()
!= 0- Specified by:
-
readBoolean
in interfaceDataInput
- 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'sread()
method.- Specified by:
-
readByte
in interfaceDataInput
- 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 character delegating toreadShort()
.- Specified by:
-
readChar
in interfaceDataInput
- 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
readDouble
public double readDouble() throws IOException, EOFException
Delegates toEndianUtils.readSwappedDouble(InputStream)
.- Specified by:
-
readDouble
in interfaceDataInput
- 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
Delegates toEndianUtils.readSwappedFloat(InputStream)
.- Specified by:
-
readFloat
in interfaceDataInput
- Returns:
- the read long
- 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'sread(byte[] data, int, int)
method.- Specified by:
-
readFully
in interfaceDataInput
- 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'sread(byte[] data, int, int)
method.- Specified by:
-
readFully
in interfaceDataInput
- 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
Delegates toEndianUtils.readSwappedInteger(InputStream)
.- Specified by:
-
readInt
in interfaceDataInput
- Returns:
- the read long
- 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 - throwsUnsupportedOperationException
.- Specified by:
-
readLine
in interfaceDataInput
- Returns:
- the line read
- Throws:
-
EOFException
- if an end of file is reached unexpectedly -
IOException
- if an I/O error occurs.
readLong
public long readLong() throws IOException, EOFException
Delegates toEndianUtils.readSwappedLong(InputStream)
.- Specified by:
-
readLong
in interfaceDataInput
- 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
Delegates toEndianUtils.readSwappedShort(InputStream)
.- Specified by:
-
readShort
in interfaceDataInput
- Returns:
- the read long
- 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'sread()
method.- Specified by:
-
readUnsignedByte
in interfaceDataInput
- 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
Delegates toEndianUtils.readSwappedUnsignedShort(InputStream)
.- Specified by:
-
readUnsignedShort
in interfaceDataInput
- Returns:
- the read long
- 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 - throwsUnsupportedOperationException
.- Specified by:
-
readUTF
in interfaceDataInput
- Returns:
- UTF String read
- Throws:
-
EOFException
- if an end of file is reached unexpectedly -
IOException
- if an I/O error occurs.
skipBytes
public int skipBytes(int count) throws IOException, EOFException
Invokes the delegate'sskip(int)
method.- Specified by:
-
skipBytes
in interfaceDataInput
- Parameters:
-
count
- the number of bytes to skip - Returns:
- the number of bytes to skipped or -1 if the end of stream
- Throws:
-
EOFException
- if an end of file is reached unexpectedly -
IOException
- if an I/O error occurs.
Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.