use of org.bson.BsonBinaryReader in project mongo-java-driver by mongodb.
the class CodecTestUtil method prepareReaderWithObjectToBeDecoded.
static <T> BsonBinaryReader prepareReaderWithObjectToBeDecoded(final T objectToDecode, final Codec<T> codec) {
BasicOutputBuffer outputBuffer = new BasicOutputBuffer();
BsonBinaryWriter writer = new BsonBinaryWriter(outputBuffer);
byte[] documentAsByteArrayForReader;
try {
codec.encode(writer, objectToDecode, EncoderContext.builder().build());
documentAsByteArrayForReader = outputBuffer.toByteArray();
} finally {
writer.close();
}
return new BsonBinaryReader(new ByteBufferBsonInput(new ByteBufNIO(wrap(documentAsByteArrayForReader))));
}
use of org.bson.BsonBinaryReader in project mongo-java-driver by mongodb.
the class DocumentCodecTest method testCodeWithScopeEncoding.
@Test
public void testCodeWithScopeEncoding() throws IOException {
DocumentCodec documentCodec = new DocumentCodec();
Document doc = new Document();
doc.put("theCode", new CodeWithScope("javaScript code", new Document("fieldNameOfScope", "valueOfScope")));
documentCodec.encode(writer, doc, EncoderContext.builder().build());
Document decodedDocument = documentCodec.decode(new BsonBinaryReader(createInputBuffer()), DecoderContext.builder().build());
assertEquals(doc, decodedDocument);
}
use of org.bson.BsonBinaryReader in project mongo-java-driver by mongodb.
the class DocumentCodecTest method testIterableContainingOtherIterableEncoding.
@Test
public void testIterableContainingOtherIterableEncoding() throws IOException {
DocumentCodec documentCodec = new DocumentCodec();
Document doc = new Document();
@SuppressWarnings("unchecked") List<List<Integer>> listOfLists = asList(asList(1), asList(2));
doc.put("array", listOfLists);
documentCodec.encode(writer, doc, EncoderContext.builder().build());
BsonInput bsonInput = createInputBuffer();
Document decodedDocument = documentCodec.decode(new BsonBinaryReader(bsonInput), DecoderContext.builder().build());
assertEquals(doc, decodedDocument);
}
use of org.bson.BsonBinaryReader in project mongo-java-driver by mongodb.
the class DocumentCodecTest method testIterableContainingDocumentsEncoding.
@Test
public void testIterableContainingDocumentsEncoding() throws IOException {
DocumentCodec documentCodec = new DocumentCodec();
Document doc = new Document();
List<Document> listOfDocuments = asList(new Document("intVal", 1), new Document("anotherInt", 2));
doc.put("array", listOfDocuments);
documentCodec.encode(writer, doc, EncoderContext.builder().build());
BsonInput bsonInput = createInputBuffer();
Document decodedDocument = documentCodec.decode(new BsonBinaryReader(bsonInput), DecoderContext.builder().build());
assertEquals(doc, decodedDocument);
}
Aggregations