use of com.mongodb.connection.ByteBufferBsonOutput in project mongo-java-driver by mongodb.
the class DBDecoderAdapter method decode.
@Override
public DBObject decode(final BsonReader reader, final DecoderContext decoderContext) {
ByteBufferBsonOutput bsonOutput = new ByteBufferBsonOutput(bufferProvider);
BsonBinaryWriter binaryWriter = new BsonBinaryWriter(bsonOutput);
try {
binaryWriter.pipe(reader);
BufferExposingByteArrayOutputStream byteArrayOutputStream = new BufferExposingByteArrayOutputStream(binaryWriter.getBsonOutput().getSize());
bsonOutput.pipe(byteArrayOutputStream);
return decoder.decode(byteArrayOutputStream.getInternalBytes(), collection);
} catch (IOException e) {
// impossible with a byte array output stream
throw new MongoInternalException("An unlikely IOException thrown.", e);
} finally {
binaryWriter.close();
bsonOutput.close();
}
}
Aggregations