Java 类org.bson.BsonBinaryReader 实例源码

项目:bsoncodec    文件:AbstractTest.java   
@SuppressWarnings("resource")
protected <T> void writeReadCompare(T source, Codec<T> codec) {
    BasicOutputBuffer bsonOutput = new BasicOutputBuffer();
    BsonBinaryWriter writer = new BsonBinaryWriter(bsonOutput);
    writer.writeStartDocument();
    writer.writeName("name");
    codec.encode(writer, source, EncoderContext.builder().build());
    writer.writeEndDocument();
    writer.close();

    BsonBinaryReader reader = new BsonBinaryReader(
            ByteBuffer.wrap(bsonOutput.toByteArray()));
    reader.readStartDocument();
    assertThat(reader.readName()).isEqualTo("name");
    T readNow = codec.decode(reader, DecoderContext.builder().build());

    assertThat(readNow).isEqualTo(source);
}
项目:bson-codecs-jsr310    文件:CodecsTests.java   
private <T> T decodeValue(ByteBuffer byteBuffer, Codec<T> codec) {
    try (BsonBinaryReader reader = new BsonBinaryReader(byteBuffer)) {

        reader.readStartDocument();

        String name = reader.readName();
        assertEquals("value", name);

        return codec.decode(reader, DecoderContext.builder().build());
    }
}
项目:BsonMapper    文件:DefaultBsonMapper.java   
@Override
public <T> T readFrom(ByteBuffer byteBuffer, Class<T> targetClazz) {
    if (byteBuffer == null) {
        return null;
    }
    checkNotNull(targetClazz, NOT_NULL_MSG);
    checkIsSupportClazz(targetClazz, NOT_SUPPORT_CLAZZ_MSG + targetClazz.getName());
    BsonBinaryReader bsonBinaryReader = new BsonBinaryReader(byteBuffer);
    return BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonBinaryReader, targetClazz, bsonMapperConfig);
}
项目:BsonMapper    文件:DefaultBsonMapper.java   
@Override
public <T> T readFrom(BsonInput bsonInput, Class<T> targetClazz) {
    if (bsonInput == null) {
        return null;
    }
    checkNotNull(targetClazz, NOT_NULL_MSG);
    checkIsSupportClazz(targetClazz, NOT_SUPPORT_CLAZZ_MSG + targetClazz.getName());
    BsonBinaryReader bsonBinaryReader = new BsonBinaryReader(bsonInput);
    return BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonBinaryReader, targetClazz, bsonMapperConfig);
}
项目:BsonMapper    文件:BsonDocumentConverterTest.java   
@Test
public void testByteIOEncode() throws Exception {
    BasicOutputBuffer bsonOutput = new BasicOutputBuffer();
    BsonWriter bsonWriter = new BsonBinaryWriter(bsonOutput);
    BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonWriter, getObject());
    BsonReader bsonReader = new BsonBinaryReader(new ByteBufferBsonInput(bsonOutput.getByteBuffers().get(0)));
    BsonTest bsonTest = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonReader, BsonTest.class, BsonMapperConfig.DEFALUT);
    System.out.println(bsonTest);
}
项目:java-code-gen    文件:TestCodecs.java   
private void prepareReader() {
    writer.writeEndDocument();
    reader = new BsonBinaryReader(new ByteBufferBsonInput(buffer.getByteBuffers().get(0)));
    reader.readStartDocument();
    reader.readName();
}
项目:lumongo    文件:LumongoUtil.java   
public static Document byteArrayToMongoDocument(byte[] byteArray) {
    BsonBinaryReader bsonReader = new BsonBinaryReader(ByteBuffer.wrap(byteArray));
    return new DocumentCodec().decode(bsonReader, DecoderContext.builder().build());
}
项目:immutables    文件:Jsons.java   
static org.bson.BsonReader asBsonReader(JsonObject gson) throws IOException {
  BasicOutputBuffer buffer = new BasicOutputBuffer();
  BsonWriter writer = new BsonWriter(new BsonBinaryWriter(buffer));
  TypeAdapters.JSON_ELEMENT.write(writer, gson);
  return new BsonBinaryReader(ByteBuffer.wrap(buffer.toByteArray()));
}
项目:immutables    文件:Jsons.java   
static JsonReader asGsonReader(BsonDocument bson) {
  BasicOutputBuffer output = new BasicOutputBuffer();
  new BsonDocumentCodec().encode(new BsonBinaryWriter(output), bson, EncoderContext.builder().build());
  return new BsonReader(new BsonBinaryReader(ByteBuffer.wrap(output.toByteArray())));
}
项目:vertx-native-mongo    文件:EncoderPerfTest.java   
@Benchmark
public Object decodeMongoTest() throws Exception {
    BsonBinaryReader reader = new BsonBinaryReader(ByteBuffer.wrap(encoded));
    return new BsonDocumentCodec().decode(reader, DecoderContext.builder().build());
}