Search in sources :

Example 1 with OutputBuffer

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

the class BasicBSONEncoder method encode.

@Override
public byte[] encode(final BSONObject document) {
    OutputBuffer outputBuffer = new BasicOutputBuffer();
    set(outputBuffer);
    putObject(document);
    done();
    return outputBuffer.toByteArray();
}
Also used : BasicOutputBuffer(org.bson.io.BasicOutputBuffer) OutputBuffer(org.bson.io.OutputBuffer) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

Example 2 with OutputBuffer

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

the class CodecTestCase method encode.

<T> OutputBuffer encode(final Codec<T> codec, final T value) {
    OutputBuffer buffer = new BasicOutputBuffer();
    BsonWriter writer = new BsonBinaryWriter(buffer);
    codec.encode(writer, value, EncoderContext.builder().build());
    return buffer;
}
Also used : BsonWriter(org.bson.BsonWriter) BsonBinaryWriter(org.bson.BsonBinaryWriter) BasicOutputBuffer(org.bson.io.BasicOutputBuffer) OutputBuffer(org.bson.io.OutputBuffer) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

Example 3 with OutputBuffer

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

the class PojoTestCase method decodesTo.

<T> void decodesTo(final Codec<T> codec, final String json, final T expected) {
    OutputBuffer encoded = encode(DOCUMENT_CODEC, BsonDocument.parse(json), false);
    T result = decode(codec, encoded);
    assertEquals("Decoded value", expected, result);
}
Also used : OutputBuffer(org.bson.io.OutputBuffer) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

Example 4 with OutputBuffer

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

the class PojoTestCase method encode.

<T> OutputBuffer encode(final Codec<T> codec, final T value, final boolean collectible) {
    OutputBuffer buffer = new BasicOutputBuffer();
    BsonWriter writer = new BsonBinaryWriter(buffer);
    codec.encode(writer, value, EncoderContext.builder().isEncodingCollectibleDocument(collectible).build());
    return buffer;
}
Also used : BsonWriter(org.bson.BsonWriter) BsonBinaryWriter(org.bson.BsonBinaryWriter) OutputBuffer(org.bson.io.OutputBuffer) BasicOutputBuffer(org.bson.io.BasicOutputBuffer) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

Example 5 with OutputBuffer

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

the class PojoTestCase method encodesTo.

@SuppressWarnings("unchecked")
<T> void encodesTo(final Codec<T> codec, final T value, final String json, final boolean collectible) {
    OutputBuffer encoded = encode(codec, value, collectible);
    BsonDocument asBsonDocument = decode(DOCUMENT_CODEC, encoded);
    assertEquals("Encoded value", BsonDocument.parse(json), asBsonDocument);
}
Also used : BsonDocument(org.bson.BsonDocument) OutputBuffer(org.bson.io.OutputBuffer) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

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