Search in sources :

Example 1 with ByteBufferBsonOutput

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();
    }
}
Also used : BsonBinaryWriter(org.bson.BsonBinaryWriter) IOException(java.io.IOException) ByteBufferBsonOutput(com.mongodb.connection.ByteBufferBsonOutput)

Aggregations

ByteBufferBsonOutput (com.mongodb.connection.ByteBufferBsonOutput)1 IOException (java.io.IOException)1 BsonBinaryWriter (org.bson.BsonBinaryWriter)1