Package com.google.common.io
Class LittleEndianDataInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- com.google.common.io.LittleEndianDataInputStream
-
- All Implemented Interfaces:
Closeable
,DataInput
,AutoCloseable
@GwtIncompatible public final class LittleEndianDataInputStream extends FilterInputStream implements DataInput
An implementation ofDataInput
that uses little-endian byte ordering for readingshort
,int
,float
,double
, andlong
values.Note: This class intentionally violates the specification of its supertype
DataInput
, which explicitly requires big-endian byte order.- Since:
- 8.0
- Author:
- Chris Nokleberg, Keith Bottner
-
-
Field Summary
-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description LittleEndianDataInputStream(InputStream in)
Creates aLittleEndianDataInputStream
that wraps the given stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
readBoolean()
byte
readByte()
char
readChar()
Reads a char as specified byDataInputStream.readChar()
, except using little-endian byte order.double
readDouble()
Reads adouble
as specified byDataInputStream.readDouble()
, except using little-endian byte order.float
readFloat()
Reads afloat
as specified byDataInputStream.readFloat()
, except using little-endian byte order.void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
Reads an integer as specified byDataInputStream.readInt()
, except using little-endian byte order.String
readLine()
This method will throw anUnsupportedOperationException
.long
readLong()
Reads along
as specified byDataInputStream.readLong()
, except using little-endian byte order.short
readShort()
Reads ashort
as specified byDataInputStream.readShort()
, except using little-endian byte order.int
readUnsignedByte()
int
readUnsignedShort()
Reads an unsignedshort
as specified byDataInputStream.readUnsignedShort()
, except using little-endian byte order.String
readUTF()
int
skipBytes(int n)
-
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, read, reset, skip
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
LittleEndianDataInputStream
public LittleEndianDataInputStream(InputStream in)
Creates aLittleEndianDataInputStream
that wraps the given stream.- Parameters:
in
- the stream to delegate to
-
-
Method Detail
-
readLine
@CanIgnoreReturnValue public String readLine()
This method will throw anUnsupportedOperationException
.
-
readFully
public void readFully(byte[] b) throws IOException
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException
- Specified by:
skipBytes
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
@CanIgnoreReturnValue public int readUnsignedByte() throws IOException
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readUnsignedShort
@CanIgnoreReturnValue public int readUnsignedShort() throws IOException
Reads an unsignedshort
as specified byDataInputStream.readUnsignedShort()
, except using little-endian byte order.- Specified by:
readUnsignedShort
in interfaceDataInput
- Returns:
- the next two bytes of the input stream, interpreted as an unsigned 16-bit integer in little-endian byte order
- Throws:
IOException
- if an I/O error occurs
-
readInt
@CanIgnoreReturnValue public int readInt() throws IOException
Reads an integer as specified byDataInputStream.readInt()
, except using little-endian byte order.- Specified by:
readInt
in interfaceDataInput
- Returns:
- the next four bytes of the input stream, interpreted as an
int
in little-endian byte order - Throws:
IOException
- if an I/O error occurs
-
readLong
@CanIgnoreReturnValue public long readLong() throws IOException
Reads along
as specified byDataInputStream.readLong()
, except using little-endian byte order.- Specified by:
readLong
in interfaceDataInput
- Returns:
- the next eight bytes of the input stream, interpreted as a
long
in little-endian byte order - Throws:
IOException
- if an I/O error occurs
-
readFloat
@CanIgnoreReturnValue public float readFloat() throws IOException
Reads afloat
as specified byDataInputStream.readFloat()
, except using little-endian byte order.- Specified by:
readFloat
in interfaceDataInput
- Returns:
- the next four bytes of the input stream, interpreted as a
float
in little-endian byte order - Throws:
IOException
- if an I/O error occurs
-
readDouble
@CanIgnoreReturnValue public double readDouble() throws IOException
Reads adouble
as specified byDataInputStream.readDouble()
, except using little-endian byte order.- Specified by:
readDouble
in interfaceDataInput
- Returns:
- the next eight bytes of the input stream, interpreted as a
double
in little-endian byte order - Throws:
IOException
- if an I/O error occurs
-
readUTF
@CanIgnoreReturnValue public String readUTF() throws IOException
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
readShort
@CanIgnoreReturnValue public short readShort() throws IOException
Reads ashort
as specified byDataInputStream.readShort()
, except using little-endian byte order.- Specified by:
readShort
in interfaceDataInput
- Returns:
- the next two bytes of the input stream, interpreted as a
short
in little-endian byte order. - Throws:
IOException
- if an I/O error occurs.
-
readChar
@CanIgnoreReturnValue public char readChar() throws IOException
Reads a char as specified byDataInputStream.readChar()
, except using little-endian byte order.- Specified by:
readChar
in interfaceDataInput
- Returns:
- the next two bytes of the input stream, interpreted as a
char
in little-endian byte order - Throws:
IOException
- if an I/O error occurs
-
readByte
@CanIgnoreReturnValue public byte readByte() throws IOException
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readBoolean
@CanIgnoreReturnValue public boolean readBoolean() throws IOException
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
-