public class BsonInputStream extends FilterInputStream
BsonInputStream provides a class to read BSON documents based on the
 BSON specification.| Modifier and Type | Field and Description | 
|---|---|
static Charset | 
UTF8
UTF-8 Character set for encoding strings. 
 | 
in| Constructor and Description | 
|---|
BsonInputStream(InputStream input)
Creates a BSON document reader. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
long | 
getBytesRead()
Returns the number of bytes that have been read by the stream. 
 | 
int | 
read() | 
int | 
read(byte[] b) | 
int | 
read(byte[] b,
    int off,
    int len) | 
protected ArrayElement | 
readArrayElement()
Reads a BSON Array element:  
 | 
protected BinaryElement | 
readBinaryElement()
Reads a  
BinaryElement's contents:  | 
String | 
readCString()
Reads a "cstring" value from the stream: 
 | 
Document | 
readDocument()
Reads a BSON document element:  
 | 
protected DocumentElement | 
readDocumentElement()
Reads a BSON Subdocument element:  
 | 
protected Element | 
readElement(byte token)
Reads the element: 
 | 
protected List<Element> | 
readElements()
Reads a BSON element list (e_list):  
 | 
protected void | 
readFully(byte[] buffer)
Reads the complete set of bytes from the stream or throws an
  
EOFException. | 
int | 
readInt()
Reads a little-endian 4 byte signed integer from the stream. 
 | 
long | 
readLong()
Reads a little-endian 8 byte signed integer from the stream. 
 | 
protected String | 
readString()
Reads a "string" value from the stream: 
 | 
long | 
skip(long n) | 
available, close, mark, markSupported, resetpublic static final Charset UTF8
public BsonInputStream(InputStream input)
input - the underlying stream to read from.public long getBytesRead()
public int read()
         throws IOException
Overridden to track the bytes that have been read.
read in class FilterInputStreamIOExceptionpublic int read(byte[] b)
         throws IOException
Overridden to track the bytes that have been read.
read in class FilterInputStreamIOExceptionpublic int read(byte[] b,
       int off,
       int len)
         throws IOException
Overridden to track the bytes that have been read.
read in class FilterInputStreamIOExceptionpublic String readCString() throws EOFException, IOException
 
 cstring        ::=     (byte*) "\x00"
 
 
 
CString - Zero or more modified UTF-8 encoded characters followed by '\x00'. The (byte*) MUST NOT contain '\x00', hence it is not full UTF-8.
EOFException - On insufficient data for the integer.IOException - On a failure reading the integer.public Document readDocument() throws EOFException, IOException
 
 document       ::=     int32 e_list "\x00"
 
 EOFException - On insufficient data for the document.IOException - On a failure reading the document.public int readInt()
            throws EOFException,
                   IOException
EOFException - On insufficient data for the integer.IOException - On a failure reading the integer.public long readLong()
              throws EOFException,
                     IOException
EOFException - On insufficient data for the long.IOException - On a failure reading the long.public long skip(long n)
          throws IOException
Overridden to track the bytes that have been skipped.
skip in class FilterInputStreamIOExceptionprotected ArrayElement readArrayElement() throws EOFException, IOException
 
 "\x04" e_name document
 
 ArrayElement.EOFException - On insufficient data for the document.IOException - On a failure reading the document.protected BinaryElement readBinaryElement() throws EOFException, IOException
BinaryElement's contents: 
 binary         ::=     int32 subtype (byte*)   
 subtype        ::=     "\x00"  Binary / Generic
                   |    "\x01"  Function
                   |    "\x02"  Binary (Old)
                   |    "\x03"  UUID
                   |    "\x05"  MD5
                   |    "\x80"  User defined
 
 BinaryElement.EOFException - On insufficient data for the binary data.IOException - On a failure reading the binary data.protected DocumentElement readDocumentElement() throws EOFException, IOException
 
 "\x03" e_name document
 
 ArrayElement.EOFException - On insufficient data for the document.IOException - On a failure reading the document.protected Element readElement(byte token) throws EOFException, IOException
 
 element        ::=     "\x01" e_name double                    Floating point
                   |    "\x02" e_name string                    UTF-8 string
                   |    "\x03" e_name document                  Embedded document
                   |    "\x04" e_name document                  Array
                   |    "\x05" e_name binary                    Binary data
                   |    "\x06" e_name                                   Undefined — Deprecated
                   |    "\x07" e_name (byte*12)                 ObjectId
                   |    "\x08" e_name "\x00"                    Boolean "false"
                   |    "\x08" e_name "\x01"                    Boolean "true"
                   |    "\x09" e_name int64                     UTC datetime
                   |    "\x0A" e_name                                   Null value
                   |    "\x0B" e_name cstring cstring   Regular expression
                   |    "\x0C" e_name string (byte*12)  DBPointer — Deprecated
                   |    "\x0D" e_name string                    JavaScript code
                   |    "\x0E" e_name string                    Symbol
                   |    "\x0F" e_name code_w_s                  JavaScript code w/ scope
                   |    "\x10" e_name int32                     32-bit Integer
                   |    "\x11" e_name int64                     Timestamp
                   |    "\x12" e_name int64                     64-bit integer
                   |    "\xFF" e_name                                   Min key
                   |    "\x7F" e_name                                   Max key
 
 token - The element's token.EOFException - On insufficient data for the binary data.IOException - On a failure reading the binary data.protected List<Element> readElements() throws EOFException, IOException
 
 e_list         ::=     element e_list | ""     
 
 EOFException - On insufficient data for the elements.IOException - On a failure reading the elements.protected void readFully(byte[] buffer)
                  throws EOFException,
                         IOException
EOFException.buffer - The buffer into which the data is read.EOFException - If the input stream reaches the end before reading all the
                bytes.IOException - On an error reading from the underlying stream.protected String readString() throws EOFException, IOException
 
 string         ::=     int32 (byte*) "\x00"
 
 
 
String - The int32 is the number bytes in the (byte*) + 1 (for the trailing '\x00'). The (byte*) is zero or more UTF-8 encoded characters.
EOFException - On insufficient data for the integer.IOException - On a failure reading the integer.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.