Search in sources :

Example 11 with OutputBuffer

use of org.bson.io.OutputBuffer in project mongo-java-driver by mongodb.

the class CodecTestCase method roundTripWithRegistry.

@SuppressWarnings("unchecked")
<T> void roundTripWithRegistry(final T value, final Comparator<T> comparator, final CodecRegistry codecRegistry) {
    Codec<T> codec = (Codec<T>) codecRegistry.get(value.getClass());
    OutputBuffer encoded = encode(codec, value);
    T decoded = decode(codec, encoded);
    comparator.apply(decoded);
}
Also used : BasicOutputBuffer(org.bson.io.BasicOutputBuffer) OutputBuffer(org.bson.io.OutputBuffer)

Example 12 with OutputBuffer

use of org.bson.io.OutputBuffer in project mongo-java-driver by mongodb.

the class LazyDBEncoderTest method testEncodingObject.

@Test
public void testEncodingObject() {
    byte[] bytes = new byte[] { 12, 0, 0, 0, 16, 97, 0, 1, 0, 0, 0, 0 };
    DBObject document = new LazyDBObject(bytes, new LazyDBCallback(null));
    OutputBuffer buffer = new BasicOutputBuffer();
    new LazyDBEncoder().writeObject(buffer, document);
    assertArrayEquals(bytes, buffer.toByteArray());
}
Also used : OutputBuffer(org.bson.io.OutputBuffer) BasicOutputBuffer(org.bson.io.BasicOutputBuffer) BasicOutputBuffer(org.bson.io.BasicOutputBuffer) Test(org.junit.Test)

Aggregations

BasicOutputBuffer (org.bson.io.BasicOutputBuffer)12 OutputBuffer (org.bson.io.OutputBuffer)12 BsonBinaryWriter (org.bson.BsonBinaryWriter)5 BsonDocument (org.bson.BsonDocument)3 ByteBuffer (java.nio.ByteBuffer)2 BsonWriter (org.bson.BsonWriter)2 ByteBufNIO (org.bson.ByteBufNIO)2 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)2 JsonReader (org.bson.json.JsonReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.Test)1