com.mindprod.ledatastream
Class LEDataInputStream

java.lang.Object
  extended by com.mindprod.ledatastream.LEDataInputStream
All Implemented Interfaces:
java.io.DataInput

public final class LEDataInputStream
extends java.lang.Object
implements java.io.DataInput

Little-Endian version of DataInputStream.

Very similar to DataInputStream except it reads little-endian instead of big-endian binary data. We can't extend DataInputStream directly since it has only final methods, though DataInputStream itself is not final. This forces us implement LEDataInputStream with a DataInputStream object, and use wrapper methods.

Since:
1998
Version:
1.8 2007-05-24
Author:
Roedy Green, Canadian Mind Products

Field Summary
protected  java.io.DataInputStream dis
          to get at the big-Endian methods of a basic DataInputStream
protected  java.io.InputStream is
          to get at the a basic readBytes method.
protected  byte[] work
          work array for buffering input.
 
Constructor Summary
LEDataInputStream(java.io.InputStream in)
          constructor.
 
Method Summary
 void close()
          close.
 int read(byte[] ba, int off, int len)
          Read bytes.
 boolean readBoolean()
          read only a one-byte boolean.
 byte readByte()
          read byte.
 char readChar()
          Read on char.
 double readDouble()
          Read a double.
 float readFloat()
          Read one float.
 void readFully(byte[] ba)
          Read bytes until the array is filled.
 void readFully(byte[] ba, int off, int len)
          Read bytes until the count is satisfied.
 int readInt()
          Read an int, 32-bits.
 java.lang.String readLine()
          Deprecated. This method does not properly convert bytes to characters. Use a Reader instead with a little-endian encoding.
 long readLong()
          read a long, 64-bits.
 short readShort()
          Read short, 16-bits.
 int readUnsignedByte()
          Read an unsigned byte.
 int readUnsignedShort()
          Read an unsigned short, 16 bits.
 java.lang.String readUTF()
          Read UTF counted string.
static java.lang.String readUTF(java.io.DataInput in)
          Note.
 int skipBytes(int n)
          Skip over bytes in the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dis

protected final java.io.DataInputStream dis
to get at the big-Endian methods of a basic DataInputStream


is

protected final java.io.InputStream is
to get at the a basic readBytes method.


work

protected final byte[] work
work array for buffering input.

Constructor Detail

LEDataInputStream

public LEDataInputStream(java.io.InputStream in)
constructor.

Parameters:
in - binary inputstream of little-endian data.
Method Detail

readUTF

public static java.lang.String readUTF(java.io.DataInput in)
                                throws java.io.IOException
Note. This is a STATIC method!

Parameters:
in - stream to read UTF chars from (endian irrelevant)
Returns:
string from stream
Throws:
java.io.IOException - if read fails.

close

public final void close()
                 throws java.io.IOException
close.

Throws:
java.io.IOException - if close fails.

read

public final int read(byte[] ba,
                      int off,
                      int len)
               throws java.io.IOException
Read bytes. Watch out, read may return fewer bytes than requested.

Parameters:
ba - where the bytes go.
off - offset in buffer, not offset in file.
len - count of bytes to read.
Returns:
how many bytes read.
Throws:
java.io.IOException - if read fails.

readBoolean

public final boolean readBoolean()
                          throws java.io.IOException
read only a one-byte boolean.

Specified by:
readBoolean in interface java.io.DataInput
Returns:
true or false.
Throws:
java.io.IOException - if read fails.
See Also:
DataInput.readBoolean()

readByte

public final byte readByte()
                    throws java.io.IOException
read byte.

Specified by:
readByte in interface java.io.DataInput
Returns:
the byte read.
Throws:
java.io.IOException - if read fails.
See Also:
DataInput.readByte()

readChar

public final char readChar()
                    throws java.io.IOException
Read on char. like DataInputStream.readChar except little endian.

Specified by:
readChar in interface java.io.DataInput
Returns:
little endian 16-bit unicode char from the stream.
Throws:
java.io.IOException - if read fails.

readDouble

public final double readDouble()
                        throws java.io.IOException
Read a double. like DataInputStream.readDouble except little endian.

Specified by:
readDouble in interface java.io.DataInput
Returns:
little endian IEEE double from the datastream.
Throws:
java.io.IOException

readFloat

public final float readFloat()
                      throws java.io.IOException
Read one float. Like DataInputStream.readFloat except little endian.

Specified by:
readFloat in interface java.io.DataInput
Returns:
little endian IEEE float from the datastream.
Throws:
java.io.IOException - if read fails.

readFully

public final void readFully(byte[] ba)
                     throws java.io.IOException
Read bytes until the array is filled.

Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readFully(byte[])

readFully

public final void readFully(byte[] ba,
                            int off,
                            int len)
                     throws java.io.IOException
Read bytes until the count is satisfied.

Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException - if read fails.
See Also:
DataInput.readFully(byte[],int,int)

readInt

public final int readInt()
                  throws java.io.IOException
Read an int, 32-bits. Like DataInputStream.readInt except little endian.

Specified by:
readInt in interface java.io.DataInput
Returns:
little-endian binary int from the datastream
Throws:
java.io.IOException - if read fails.

readLine

public final java.lang.String readLine()
                                throws java.io.IOException
Deprecated. This method does not properly convert bytes to characters. Use a Reader instead with a little-endian encoding.

Read a line.

Specified by:
readLine in interface java.io.DataInput
Returns:
a rough approximation of the 8-bit stream as a 16-bit unicode string
Throws:
java.io.IOException

readLong

public final long readLong()
                    throws java.io.IOException
read a long, 64-bits. Like DataInputStream.readLong except little endian.

Specified by:
readLong in interface java.io.DataInput
Returns:
little-endian binary long from the datastream.
Throws:
java.io.IOException

readShort

public final short readShort()
                      throws java.io.IOException
Read short, 16-bits. Like DataInputStream.readShort except little endian.

Specified by:
readShort in interface java.io.DataInput
Returns:
little endian binary short from stream.
Throws:
java.io.IOException - if read fails.

readUTF

public final java.lang.String readUTF()
                               throws java.io.IOException
Read UTF counted string.

Specified by:
readUTF in interface java.io.DataInput
Returns:
String read.
Throws:
java.io.IOException

readUnsignedByte

public final int readUnsignedByte()
                           throws java.io.IOException
Read an unsigned byte. Note: returns an int, even though says Byte (non-Javadoc)

Specified by:
readUnsignedByte in interface java.io.DataInput
Throws:
java.io.IOException - if read fails.
See Also:
DataInput.readUnsignedByte()

readUnsignedShort

public final int readUnsignedShort()
                            throws java.io.IOException
Read an unsigned short, 16 bits. Like DataInputStream.readUnsignedShort except little endian. Note, returns int even though it reads a short.

Specified by:
readUnsignedShort in interface java.io.DataInput
Returns:
little-endian int from the stream.
Throws:
java.io.IOException - if read fails.

skipBytes

public final int skipBytes(int n)
                    throws java.io.IOException
Skip over bytes in the stream. See the general contract of the skipBytes method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
skipBytes in interface java.io.DataInput
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException - if an I/O error occurs.