@Override public void doWriteObjectId(final ObjectId value) { bsonOutput.writeByte(BsonType.OBJECT_ID.getValue()); writeCurrentName(); bsonOutput.writeBytes(value.toByteArray()); }
@Override public void compress(final List<ByteBuf> source, final BsonOutput target) { int uncompressedSize = getUncompressedSize(source); byte[] singleByteArraySource = new byte[uncompressedSize]; copy(source, singleByteArraySource); try { byte[] out = new byte[Snappy.maxCompressedLength(uncompressedSize)]; int compressedSize = Snappy.compress(singleByteArraySource, 0, singleByteArraySource.length, out, 0); target.writeBytes(out, 0, compressedSize); } catch (IOException e) { throw new MongoInternalException("Unexpected IOException", e); } }
void compress(final List<ByteBuf> source, final BsonOutput target) { BufferExposingByteArrayOutputStream baos = new BufferExposingByteArrayOutputStream(1024); OutputStream outputStream = null; try { outputStream = getOutputStream(baos); byte[] scratch = new byte[BUFFER_SIZE]; for (ByteBuf cur : source) { while (cur.hasRemaining()) { int numBytes = Math.min(cur.remaining(), scratch.length); cur.get(scratch, 0, numBytes); outputStream.write(scratch, 0, numBytes); } } } catch (IOException e) { throw new MongoInternalException("Unexpected IOException", e); } finally { try { if (outputStream != null) { outputStream.close(); } } catch (IOException e) { // ignore } } target.writeBytes(baos.getInternalBytes(), 0, baos.size()); }
@Override protected void doWriteDBPointer(final BsonDbPointer value) { bsonOutput.writeByte(BsonType.DB_POINTER.getValue()); writeCurrentName(); bsonOutput.writeString(value.getNamespace()); bsonOutput.writeBytes(value.getId().toByteArray()); }
@Override protected void doWriteBinaryData(final BsonBinary value) { bsonOutput.writeByte(BsonType.BINARY.getValue()); writeCurrentName(); int totalLen = value.getData().length; if (value.getType() == BsonBinarySubType.OLD_BINARY.getValue()) { totalLen += 4; } bsonOutput.writeInt32(totalLen); bsonOutput.writeByte(value.getType()); if (value.getType() == BsonBinarySubType.OLD_BINARY.getValue()) { bsonOutput.writeInt32(totalLen - 4); } bsonOutput.writeBytes(value.getData()); }
byte[] bytes = new byte[size - 4]; bsonInput.readBytes(bytes); bsonOutput.writeBytes(bytes);
void compress(final List<ByteBuf> source, final BsonOutput target) { BufferExposingByteArrayOutputStream baos = new BufferExposingByteArrayOutputStream(1024); OutputStream outputStream = null; try { outputStream = getOutputStream(baos); byte[] scratch = new byte[BUFFER_SIZE]; for (ByteBuf cur : source) { while (cur.hasRemaining()) { int numBytes = Math.min(cur.remaining(), scratch.length); cur.get(scratch, 0, numBytes); outputStream.write(scratch, 0, numBytes); } } } catch (IOException e) { throw new MongoInternalException("Unexpected IOException", e); } finally { try { if (outputStream != null) { outputStream.close(); } } catch (IOException e) { // ignore } } target.writeBytes(baos.getInternalBytes(), 0, baos.size()); }
@Override public void compress(final List<ByteBuf> source, final BsonOutput target) { int uncompressedSize = getUncompressedSize(source); byte[] singleByteArraySource = new byte[uncompressedSize]; copy(source, singleByteArraySource); try { byte[] out = new byte[Snappy.maxCompressedLength(uncompressedSize)]; int compressedSize = Snappy.compress(singleByteArraySource, 0, singleByteArraySource.length, out, 0); target.writeBytes(out, 0, compressedSize); } catch (IOException e) { throw new MongoInternalException("Unexpected IOException", e); } }