org.jopendocument.io
Class LittleEndianInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by org.jopendocument.io.LittleEndianInputStream
All Implemented Interfaces:
Closeable

public class LittleEndianInputStream
extends FilterInputStream


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
LittleEndianInputStream(InputStream in)
          Creates a new little endian input stream and chains it to the input stream specified by the in argument.
 
Method Summary
 boolean readBoolean()
          Reads a boolean from the underlying input stream by reading a single byte.
 byte readByte(int b)
          Reads a signed byte from the underlying input stream with value between -128 and 127
 char readChar()
          Reads a two byte Unicode char from the underlying input stream in little endian order, low byte first.
 double readDouble()
           
 float readFloat()
           
 int readInt()
          Reads a four byte signed int from the underlying input stream in little endian order, low byte first.
 long readLong()
          Reads an eight byte signed int from the underlying input stream in little endian order, low byte first.
 short readShort()
          Reads a two byte signed short from the underlying input stream in little endian order, low byte first.
 int readUnsignedByte()
          Reads an unsigned byte from the underlying input stream with value between 0 and 255
 int readUnsignedShort()
          Reads a two byte unsigned short from the underlying input stream in little endian order, low byte first.
 String readUTF()
          Reads a string of no more than 65,535 characters from the underlying input stream using UTF-8 encoding.
 int skipBytes(int n)
          Skip exactly n bytes of input in the underlying input stream.
 
Methods inherited from class java.io.FilterInputStream
available, close, 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

LittleEndianInputStream

public LittleEndianInputStream(InputStream in)
Creates a new little endian input stream and chains it to the input stream specified by the in argument.

Parameters:
in - the underlying input stream.
See Also:
java.io.FilterInputStream#out
Method Detail

readBoolean

public boolean readBoolean()
                    throws IOException
Reads a boolean from the underlying input stream by reading a single byte. If the byte is zero, false is returned. If the byte is positive, true is returned.

Returns:
b the boolean value read.
Throws:
EOFException - if the end of the underlying input stream has been reached
IOException - if the underlying stream throws an IOException.

readByte

public byte readByte(int b)
              throws IOException
Reads a signed byte from the underlying input stream with value between -128 and 127

Returns:
the byte value read.
Throws:
EOFException - if the end of the underlying input stream has been reached
IOException - if the underlying stream throws an IOException.

readUnsignedByte

public int readUnsignedByte()
                     throws IOException
Reads an unsigned byte from the underlying input stream with value between 0 and 255

Returns:
the byte value read.
Throws:
EOFException - if the end of the underlying input stream has been reached
IOException - if the underlying stream throws an IOException.

readShort

public short readShort()
                throws IOException
Reads a two byte signed short from the underlying input stream in little endian order, low byte first.

Returns:
the short read.
Throws:
EOFException - if the end of the underlying input stream has been reached
IOException - if the underlying stream throws an IOException.

readUnsignedShort

public int readUnsignedShort()
                      throws IOException
Reads a two byte unsigned short from the underlying input stream in little endian order, low byte first.

Returns:
the int value of the unsigned short read.
Throws:
EOFException - if the end of the underlying input stream has been reached
IOException - if the underlying stream throws an IOException.

readChar

public char readChar()
              throws IOException
Reads a two byte Unicode char from the underlying input stream in little endian order, low byte first.

Returns:
the int value of the unsigned short read.
Throws:
EOFException - if the end of the underlying input stream has been reached
IOException - if the underlying stream throws an IOException.

readInt

public int readInt()
            throws IOException
Reads a four byte signed int from the underlying input stream in little endian order, low byte first.

Returns:
the int read.
Throws:
EOFException - if the end of the underlying input stream has been reached
IOException - if the underlying stream throws an IOException.

readLong

public long readLong()
              throws IOException
Reads an eight byte signed int from the underlying input stream in little endian order, low byte first.

Returns:
the int read.
Throws:
EOFException - if the end of the underlying input stream has been reached
IOException - if the underlying stream throws an IOException.

readUTF

public String readUTF()
               throws IOException
Reads a string of no more than 65,535 characters from the underlying input stream using UTF-8 encoding. This method first reads a two byte short in big endian order as required by the UTF-8 specification. This gives the number of bytes in the UTF-8 encoded version of the string. Next this many bytes are read and decoded as UTF-8 encoded characters.

Returns:
the decoded string
Throws:
UTFDataFormatException - if the string cannot be decoded
IOException - if the underlying stream throws an IOException.

readDouble

public final double readDouble()
                        throws IOException
Returns:
the next eight bytes of this input stream, interpreted as a little endian double.
Throws:
EOFException - if end of stream occurs before eight bytes have been read.
IOException - if an I/O error occurs.

readFloat

public final float readFloat()
                      throws IOException
Returns:
the next four bytes of this input stream, interpreted as a little endian int.
Throws:
EOFException - if end of stream occurs before four bytes have been read.
IOException - if an I/O error occurs.

skipBytes

public final int skipBytes(int n)
                    throws IOException
Skip exactly n bytes of input in the underlying input stream. This method blocks until all the bytes are skipped, the end of the stream is detected, or an exception is thrown.

Parameters:
n - the number of bytes to skip.
Returns:
the number of bytes skipped, generally n
Throws:
EOFException - if this input stream reaches the end before skipping all the bytes.
IOException - if the underlying stream throws an IOException.


Copyright © 2010 jOpenDocument All Rights Reserved.