use of org.bson.io.BasicOutputBuffer in project mongo-java-driver by mongodb.
the class BSONTest method shouldClearCustomEncoders.
@Test(expected = IllegalArgumentException.class)
public void shouldClearCustomEncoders() throws IOException {
// given
BSON.addEncodingHook(TestDate.class, new TestDateTransformer());
BSONEncoder encoder = new BasicBSONEncoder();
encoder.set(new BasicOutputBuffer());
// when
BSON.clearEncodingHooks();
encoder.putObject(new BasicBSONObject("date", new TestDate(2009, 1, 23, 10, 53, 42)));
}
use of org.bson.io.BasicOutputBuffer in project mongo-java-driver by mongodb.
the class BSONTest method testOBBig1.
@Test
public void testOBBig1() {
BasicOutputBuffer a = new BasicOutputBuffer();
StringBuilder b = new StringBuilder();
for (final String x : prepareData()) {
a.write(x.getBytes());
b.append(x);
}
assertEquals(new String(a.toByteArray(), Charset.forName("UTF-8")), b.toString());
}
use of org.bson.io.BasicOutputBuffer in project immutables by immutables.
the class BsonEncoding method unmarshalDbObject.
public static <T> T unmarshalDbObject(DBObject dbObject, TypeAdapter<T> adaper) throws IOException {
BasicOutputBuffer buffer = new BasicOutputBuffer();
encoder().writeObject(buffer, dbObject);
BsonParser parser = BSON_FACTORY.createParser(buffer.toByteArray());
BsonReader reader = new BsonReader(parser);
T instance = adaper.read(reader);
reader.close();
return instance;
}
use of org.bson.io.BasicOutputBuffer in project mongo-java-driver by mongodb.
the class ClientMetadataHelper method clientMetadataDocumentTooLarge.
static boolean clientMetadataDocumentTooLarge(final BsonDocument document) {
BasicOutputBuffer buffer = new BasicOutputBuffer(MAXIMUM_CLIENT_METADATA_ENCODED_SIZE);
new BsonDocumentCodec().encode(new BsonBinaryWriter(buffer), document, EncoderContext.builder().build());
return buffer.getPosition() > MAXIMUM_CLIENT_METADATA_ENCODED_SIZE;
}
use of org.bson.io.BasicOutputBuffer in project mongo-java-driver by mongodb.
the class RawBsonDocumentCodec method decode.
@Override
public RawBsonDocument decode(final BsonReader reader, final DecoderContext decoderContext) {
BasicOutputBuffer buffer = new BasicOutputBuffer(0);
BsonBinaryWriter writer = new BsonBinaryWriter(buffer);
try {
writer.pipe(reader);
return new RawBsonDocument(buffer.getInternalBuffer(), 0, buffer.getPosition());
} finally {
writer.close();
buffer.close();
}
}
Aggregations