本文整理汇总了Java中org.bson.BsonBinaryWriter类的典型用法代码示例。如果您正苦于以下问题:Java BsonBinaryWriter类的具体用法?Java BsonBinaryWriter怎么用?Java BsonBinaryWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonBinaryWriter类属于org.bson包,在下文中一共展示了BsonBinaryWriter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: writeReadCompare
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
@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);
}
开发者ID:ralscha,项目名称:bsoncodec,代码行数:19,代码来源:AbstractTest.java
示例2: encodeValue
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
private <T> void encodeValue(BsonOutput output, Codec<T> codec, T value) {
try (BsonBinaryWriter writer = new BsonBinaryWriter(output)) {
writer.writeStartDocument();
writer.writeName("value");
codec.encode(writer, value, EncoderContext.builder().build());
writer.writeEndDocument();
writer.close();
}
}
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:13,代码来源:CodecsTests.java
示例3: writeToBsonOutput
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
@Override
public BsonOutput writeToBsonOutput(Object object) {
if (object == null) {
return null;
}
BsonOutput bsonOutput = new BasicOutputBuffer();
BsonWriter bsonBinaryWriter = new BsonBinaryWriter(new BsonWriterSettings(bsonMapperConfig.getMaxMapperLayerNum()),
new BsonBinaryWriterSettings(bsonMapperConfig.getMaxDocumentSizeForBsonWriter()), bsonOutput);
BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonBinaryWriter, object);
return bsonOutput;
}
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:12,代码来源:DefaultBsonMapper.java
示例4: testByteIOEncode
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
@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);
}
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:10,代码来源:BsonDocumentConverterTest.java
示例5: before
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
@Before
public void before() {
buffer = new BasicOutputBuffer();
writer = new BsonBinaryWriter(buffer);
writer.writeStartDocument();
writer.writeName("test");
}
开发者ID:egopulse,项目名称:java-code-gen,代码行数:8,代码来源:TestCodecs.java
示例6: mongoDocumentToByteArray
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
public static byte[] mongoDocumentToByteArray(Document mongoDocument) {
BasicOutputBuffer outputBuffer = new BasicOutputBuffer();
BsonBinaryWriter writer = new BsonBinaryWriter(outputBuffer);
new DocumentCodec().encode(writer, mongoDocument, EncoderContext.builder().isEncodingCollectibleDocument(true).build());
return outputBuffer.toByteArray();
}
开发者ID:lumongo,项目名称:lumongo,代码行数:7,代码来源:LumongoUtil.java
示例7: asBsonReader
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
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()));
}
开发者ID:immutables,项目名称:immutables,代码行数:7,代码来源:Jsons.java
示例8: asGsonReader
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
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())));
}
开发者ID:immutables,项目名称:immutables,代码行数:6,代码来源:Jsons.java
示例9: encodeMongoTest
import org.bson.BsonBinaryWriter; //导入依赖的package包/类
@Benchmark
public Object encodeMongoTest() throws Exception {
BasicOutputBuffer out = new BasicOutputBuffer(512);
new BsonDocumentCodec().encode(new BsonBinaryWriter(out), doc1, EncoderContext.builder().build());
return out.getByteBuffers();
}
开发者ID:bckfnn,项目名称:vertx-native-mongo,代码行数:7,代码来源:EncoderPerfTest.java
注:本文中的org.bson.BsonBinaryWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论