use of org.bson.BsonBinaryReader in project immutables by immutables.
the class Jsons method asGsonReader.
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())));
}
use of org.bson.BsonBinaryReader in project mongo-flink by mongo-flink.
the class DocumentBulkSerializer method deserializeV1.
private DocumentBulk deserializeV1(DataInputDeserializer in) throws IOException {
DocumentBulk bulk = new DocumentBulk();
int len;
while ((len = in.readInt()) != END_OF_INPUT) {
byte[] docBuffer = new byte[len];
in.read(docBuffer);
BsonBinaryReader bsonReader = new BsonBinaryReader(ByteBuffer.wrap(docBuffer));
bulk.add(DOCUMENT_CODEC.decode(bsonReader, DecoderContext.builder().build()));
}
return bulk;
}
use of org.bson.BsonBinaryReader in project zuliasearch by zuliaio.
the class ZuliaUtil method byteArrayToMongoDocument.
public static Document byteArrayToMongoDocument(byte[] byteArray) {
if (byteArray != null && byteArray.length != 0) {
BsonBinaryReader bsonReader = new BsonBinaryReader(ByteBuffer.wrap(byteArray));
DecoderContext decoderContext = DecoderContext.builder().build();
if (pojoCodecRegistry != null) {
return new DocumentCodec(pojoCodecRegistry).decode(bsonReader, decoderContext);
} else {
return new DocumentCodec().decode(bsonReader, decoderContext);
}
}
return new Document();
}
use of org.bson.BsonBinaryReader in project agileway by fangjinuo.
the class Bsons method deserialize.
public static <T> T deserialize(byte[] bytes, @NonNull Class<T> targetClass) {
Preconditions.checkNotNull(targetClass);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
BsonBinaryReader reader = new BsonBinaryReader(buffer);
Codec<T> codec = codecRegistry.get(targetClass);
DecoderContext decoderContext = DecoderContext.builder().build();
T t = codec.decode(reader, decoderContext);
return t;
}
use of org.bson.BsonBinaryReader in project LanternPowerMonitor by MarkBryanMilligan.
the class DaoSerializer method fromBson.
public static DaoEntity fromBson(byte[] _btBson) {
if (_btBson == null)
return null;
BsonBinaryReader reader = null;
try {
reader = new BsonBinaryReader(ByteBuffer.wrap(_btBson).order(ByteOrder.LITTLE_ENDIAN));
Document doc = new DocumentCodec().decode(reader, DecoderContext.builder().build());
if (doc == null)
return null;
return new DaoEntity(doc);
} catch (Throwable t) {
LOG.error("Failed to convert bson to DaoEntity", t);
return null;
} finally {
if (reader != null)
reader.close();
}
}
Aggregations