de.undercouch.bson4jackson.io
Class LittleEndianInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by de.undercouch.bson4jackson.io.LittleEndianInputStream
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput

public class LittleEndianInputStream
extends java.io.FilterInputStream
implements java.io.DataInput

Works like DataInputStream but reads values using little-endian encoding. Apart from that, it provides a method that reads an UTF-8 encoded string without reading the number of bytes from the input stream.


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
LittleEndianInputStream(java.io.InputStream in)
           
 
Method Summary
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
 double readDouble()
           
 float readFloat()
           
 void readFully(byte[] b)
           
 void readFully(byte[] b, int off, int len)
           
 int readInt()
           
 java.lang.String readLine()
           
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 java.lang.String readUTF()
          Forwards to DataInputStream.readUTF(DataInput) which expects a short value at the beginning of the UTF-8 string that specifies the number of bytes to read.
 java.lang.String readUTF(java.io.DataInput input, int len)
          Reads a modified UTF-8 string from a DataInput object
 java.lang.String readUTF(int len)
          Reads a modified UTF-8 string
 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.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LittleEndianInputStream

public LittleEndianInputStream(java.io.InputStream in)
See Also:
FilterInputStream.FilterInputStream(InputStream)
Method Detail

readFully

public void readFully(byte[] b)
               throws java.io.IOException
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

skipBytes

public int skipBytes(int n)
              throws java.io.IOException
Specified by:
skipBytes in interface java.io.DataInput
Throws:
java.io.IOException

readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Specified by:
readBoolean in interface java.io.DataInput
Throws:
java.io.IOException

readByte

public byte readByte()
              throws java.io.IOException
Specified by:
readByte in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedByte

public int readUnsignedByte()
                     throws java.io.IOException
Specified by:
readUnsignedByte in interface java.io.DataInput
Throws:
java.io.IOException

readShort

public short readShort()
                throws java.io.IOException
Specified by:
readShort in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedShort

public int readUnsignedShort()
                      throws java.io.IOException
Specified by:
readUnsignedShort in interface java.io.DataInput
Throws:
java.io.IOException

readChar

public char readChar()
              throws java.io.IOException
Specified by:
readChar in interface java.io.DataInput
Throws:
java.io.IOException

readInt

public int readInt()
            throws java.io.IOException
Specified by:
readInt in interface java.io.DataInput
Throws:
java.io.IOException

readLong

public long readLong()
              throws java.io.IOException
Specified by:
readLong in interface java.io.DataInput
Throws:
java.io.IOException

readFloat

public float readFloat()
                throws java.io.IOException
Specified by:
readFloat in interface java.io.DataInput
Throws:
java.io.IOException

readDouble

public double readDouble()
                  throws java.io.IOException
Specified by:
readDouble in interface java.io.DataInput
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Specified by:
readLine in interface java.io.DataInput
Throws:
java.io.IOException

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException

Forwards to DataInputStream.readUTF(DataInput) which expects a short value at the beginning of the UTF-8 string that specifies the number of bytes to read.

If the output stream does no include such a short value, use readUTF(int) to explicitly specify the number of bytes.

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

readUTF

public java.lang.String readUTF(int len)
                         throws java.io.IOException
Reads a modified UTF-8 string

Parameters:
len - the number of bytes to read (please do not mix that up with the number of characters!). If this is -1 then the method will read bytes until the first one is zero (0x00). The zero byte will not be included in the result string.
Returns:
the UTF-8 string
Throws:
java.io.IOException - if an I/O error occurs
CharacterCodingException - if an invalid UTF-8 character has been read

readUTF

public java.lang.String readUTF(java.io.DataInput input,
                                int len)
                         throws java.io.IOException
Reads a modified UTF-8 string from a DataInput object

Parameters:
input - the DataInput object to read from
len - the number of bytes to read (please do not mix that up with the number of characters!). If this is -1 then the method will read bytes until the first one is zero (0x00). The zero byte will not be included in the result string.
Returns:
the UTF-8 string
Throws:
java.io.IOException - if an I/O error occurs
CharacterCodingException - if an invalid UTF-8 character has been read