Examples of BSONDecoder


Examples of org.bson.BSONDecoder

     * {@inheritDoc}
     *
     * @see Writable#readFields(DataInput)
     */
    public void readFields(final DataInput in) throws IOException {
        BSONDecoder dec = new BasicBSONDecoder();
        BSONCallback cb = new BasicBSONCallback();
        // Read the BSON length from the start of the record
        byte[] l = new byte[4];
        try {
            in.readFully(l);
            int dataLen = Bits.readInt(l);
            byte[] data = new byte[dataLen + 4];
            System.arraycopy(l, 0, data, 0, 4);
            in.readFully(data, 4, dataLen - 4);
            dec.decode(data, cb);
            query = (BasicBSONObject) cb.get();
            in.readFully(l);
            dataLen = Bits.readInt(l);
            data = new byte[dataLen + 4];
            System.arraycopy(l, 0, data, 0, 4);
            in.readFully(data, 4, dataLen - 4);
            dec.decode(data, cb);
            modifiers = (BasicBSONObject) cb.get();
            upsert = in.readBoolean();
            multiUpdate = in.readBoolean();
        } catch (Exception e) {
            /* If we can't read another length it's not an error, just return quietly. */
 
View Full Code Here

Examples of org.bson.BSONDecoder

     * {@inheritDoc}
     *
     * @see Writable#readFields(DataInput)
     */
    public void readFields(final DataInput in) throws IOException {
        BSONDecoder dec = new BasicBSONDecoder();
        BSONCallback cb = new BasicBSONCallback();
        // Read the BSON length from the start of the record
        byte[] l = new byte[4];
        try {
            in.readFully(l);
            int dataLen = Bits.readInt(l);
            if (LOG.isDebugEnabled()) {
                LOG.debug("*** Expected DataLen: " + dataLen);
            }
            byte[] data = new byte[dataLen + 4];
            System.arraycopy(l, 0, data, 0, 4);
            in.readFully(data, 4, dataLen - 4);
            dec.decode(data, cb);
            doc = (BSONObject) cb.get();
            if (LOG.isTraceEnabled()) {
                LOG.trace("Decoded a BSON Object: " + doc);
            }
        } catch (Exception e) {
View Full Code Here

Examples of org.bson.BSONDecoder

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        for ( int i=0; i<n; i++ )
            out.write( b );
       
        ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
        BSONDecoder d = new BasicBSONDecoder();
        for ( int i=0; i<n; i++ ){
            BSONObject x = d.readObject( in );
            assertEquals( orig , x );
        }
        assertEquals( -1 , in.read() );
    }
View Full Code Here

Examples of org.bson.BSONDecoder

        OutputBuffer buf = new BasicOutputBuffer();

        encoder.writeObject(buf, o);

        DefaultDBCallback cb = new DefaultDBCallback( null );
        BSONDecoder decoder = new BasicBSONDecoder();
        decoder.decode( buf.toByteArray() , cb );
        DBObject read = cb.dbget();

        assertEquals("{\"!\":{\"$ref\":\"hello\",\"$id\":\"world\"}}", read.toString().replaceAll( " +" , "" ));
    }
View Full Code Here

Examples of org.bson.BSONDecoder

    assertTrue(baos.size() > DynamicOutputBuffer.DEFAULT_BUFFER_SIZE * 3);
  }
 
  private void assertRaw(byte[] r) throws Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream(r);
    BSONDecoder decoder = new BasicBSONDecoder();
    BSONObject obj = decoder.readObject(bais);
    byte[] o = (byte[])obj.get("Test");
    CharBuffer buf = ByteBuffer.wrap(o).order(ByteOrder.LITTLE_ENDIAN).asCharBuffer();
    assertEquals(2, buf.remaining());
    char a = buf.get();
    char b = buf.get();
View Full Code Here

Examples of org.bson.BSONDecoder

    gen.writeEndObject();
    gen.close();
   
    byte[] r = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(r);
    BSONDecoder decoder = new BasicBSONDecoder();
    BSONObject obj = decoder.readObject(bais);
    byte[] o = (byte[])obj.get("Test");
    assertEquals(2, o.length);
    assertEquals((byte)1, o[0]);
    assertEquals((byte)2, o[1]);
  }
View Full Code Here

Examples of org.bson.BSONDecoder

    gen.writeString("a\u20AC\u00A2\u00A2bb");
    gen.writeEndObject();
    gen.close();
   
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    BSONDecoder decoder = new BasicBSONDecoder();
    BSONObject obj = decoder.readObject(bais);
    String s = (String)obj.get("a\u20AC\u00A2\u00A2bb");
    assertEquals("a\u20AC\u00A2\u00A2bb", s);
  }
View Full Code Here

Examples of org.bson.BSONDecoder

    om.writeValue(baos, data);

    byte[] r = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(r);

    BSONDecoder decoder = new BasicBSONDecoder();
    return decoder.readObject(bais);
  }
View Full Code Here

Examples of org.bson.BSONDecoder

    om.writeValue(baos, m);

    byte[] r = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(r);

    BSONDecoder decoder = new BasicBSONDecoder();
    BSONObject bo = decoder.readObject(bais);
   
    return bo.get("data");
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.