com.mindprod.ledatastream
Class LEDataInputStream

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

public final class LEDataInputStream
extends Object
implements 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  DataInputStream dis
          to get at the big-Endian methods of a basic DataInputStream
protected  InputStream is
          to get at the a basic readBytes method.
protected  byte[] work
          work array for buffering input.
 
Constructor Summary
LEDataInputStream(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.
 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.
 String readUTF()
          Read UTF counted string.
static String readUTF(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 DataInputStream dis
to get at the big-Endian methods of a basic DataInputStream


is

protected final 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(InputStream in)
constructor.

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

readUTF

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

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

close

public final void close()
                 throws IOException
close.

Throws:
IOException - if close fails.

read

public final int read(byte[] ba,
                      int off,
                      int len)
               throws 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:
IOException - if read fails.

readBoolean

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

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

readByte

public final byte readByte()
                    throws IOException
read byte.

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

readChar

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

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

readDouble

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

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

readFloat

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

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

readFully

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

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

readFully

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

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

readInt

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

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

readLine

public final String readLine()
                      throws 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 DataInput
Returns:
a rough approximation of the 8-bit stream as a 16-bit unicode string
Throws:
IOException

readLong

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

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

readShort

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

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

readUTF

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

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

readUnsignedByte

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

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

readUnsignedShort

public final int readUnsignedShort()
                            throws 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 DataInput
Returns:
little-endian int from the stream.
Throws:
IOException - if read fails.

skipBytes

public final int skipBytes(int n)
                    throws 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 DataInput
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.


Copyright © 2012. All Rights Reserved.