Package org.bson.io

Examples of org.bson.io.OutputBuffer.toByteArray()


            Object id = dbo.get("_id");
            _checkKeys(dbo);
            DBEncoder encoder = factory.create();
            OutputBuffer buffer = new BasicOutputBuffer();
            encoder.writeObject(buffer, dbo);
            return buffer.toByteArray();
        }

        private void _checkKeys(DBObject o) {
            for (String s : o.keySet()) {
                validateKey(s);
View Full Code Here


        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

        assertEquals( hash , buf.md5() );
        e.done();
       
        BSONDecoder d = new BasicBSONDecoder();
        BSONCallback cb = new BasicBSONCallback();
        int s = d.decode( new ByteArrayInputStream( buf.toByteArray() ) , cb );
        assertEquals( size , s );

        OutputBuffer buf2 = new BasicOutputBuffer();
        e.set( buf2 );
        e.putObject( (BSONObject)cb.get() );
View Full Code Here

        BSON.addEncodingHook( TestDate.class, tf );
        e.putObject( o );
        e.done();

        d.decode( new ByteArrayInputStream( buf.toByteArray() ), cb );
        Object result = cb.get();
        assertTrue( result instanceof BSONObject );
        BSONObject bson = (BSONObject) result;
        assertNotNull( bson.get( "date" ) );
        assertTrue( bson.get( "date" ) instanceof java.util.Date );
View Full Code Here

        OutputBuffer buf = new BasicOutputBuffer();
        e.set( buf );
        e.putObject( o );
        e.done();

        d.decode( new ByteArrayInputStream( buf.toByteArray() ), cb );
        Object result = cb.get();
        assertTrue( result instanceof BSONObject );
        BSONObject bson = (BSONObject) result;
        assertNotNull( bson.get( "date" ) );
        assertTrue( bson.get( "date" ) instanceof java.util.Date );
View Full Code Here

        assertNotNull( bson.get( "date" ) );
        assertTrue( bson.get( "date" ) instanceof java.util.Date );

        BSON.addDecodingHook( Date.class, tf );

        d.decode( new ByteArrayInputStream( buf.toByteArray() ), cb );
        bson = (BSONObject) cb.get();
        assertNotNull( bson.get( "date" ) );
        assertTrue( bson.get( "date" ) instanceof TestDate );
        assertEquals( bson.get( "date" ), td );
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.