use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class JsonReaderTest method testBinaryWithNumericType.
@Test
public void testBinaryWithNumericType() {
String json = "{ \"$binary\" : \"AQID\", \"$type\" : 0 }";
bsonReader = new JsonReader(json);
assertEquals(BsonType.BINARY, bsonReader.readBsonType());
BsonBinary binary = bsonReader.readBinaryData();
assertEquals(BsonBinarySubType.BINARY.getValue(), binary.getType());
assertArrayEquals(new byte[] { 1, 2, 3 }, binary.getData());
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class MaxDocumentSizeTest method setUp.
@Before
public void setUp() {
message = new InsertMessage("test.test", true, ACKNOWLEDGED, asList(new InsertRequest(new BsonDocument("bytes", new BsonBinary(new byte[2048])))), MessageSettings.builder().maxDocumentSize(1024).build());
buffer = new ByteBufferBsonOutput(new SimpleBufferProvider());
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class MaxMessageSizeTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() {
BsonBinary binary = new BsonBinary(new byte[2048]);
message = new InsertMessage("test.test", true, ACKNOWLEDGED, Arrays.asList(new InsertRequest(new BsonDocument("bytes", binary)), new InsertRequest(new BsonDocument("bytes", binary)), new InsertRequest(new BsonDocument("bytes", binary))), MessageSettings.builder().maxMessageSize(4500).build());
buffer = new ByteBufferBsonOutput(new SimpleBufferProvider());
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class GridFSTest method parseHexDocument.
private BsonDocument parseHexDocument(final BsonDocument document, final String hexDocument) {
if (document.containsKey(hexDocument) && document.get(hexDocument).isDocument()) {
byte[] bytes = DatatypeConverter.parseHexBinary(document.getDocument(hexDocument).getString("$hex").getValue());
document.put(hexDocument, new BsonBinary(bytes));
}
return document;
}
use of org.bson.BsonBinary in project drill by axbaretto.
the class BsonRecordReader method writeBinary.
private void writeBinary(BsonReader reader, final MapOrListWriterImpl writer, String fieldName, boolean isList) {
final VarBinaryHolder vb = new VarBinaryHolder();
BsonBinary readBinaryData = reader.readBinaryData();
byte[] data = readBinaryData.getData();
Byte type = (Byte) readBinaryData.getType();
// Based on specified binary type, cast it accordingly
switch(type.intValue()) {
case 1:
// Double 1
writeDouble(ByteBuffer.wrap(data).getDouble(), writer, fieldName, isList);
break;
case 2:
// String 2
writeString(new String(data), writer, fieldName, isList);
break;
case 8:
// Boolean 8
boolean boolValue = (data == null || data.length == 0) ? false : data[0] != 0x00;
writeBoolean(boolValue, writer, fieldName, isList);
break;
case 9:
// Date 9
writeDateTime(ByteBuffer.wrap(data).getLong(), writer, fieldName, isList);
break;
case 13:
// JavaScript 13
writeString(new String(data), writer, fieldName, isList);
break;
case 14:
// Symbol 14
writeString(new String(data), writer, fieldName, isList);
break;
case 15:
// JavaScript (with scope) 15
writeString(new String(data), writer, fieldName, isList);
break;
case 16:
// 32-bit integer 16
writeInt32(ByteBuffer.wrap(data).getInt(), writer, fieldName, isList);
break;
case 17:
// Timestamp 17
writeTimeStamp(ByteBuffer.wrap(data).getInt(), writer, fieldName, isList);
break;
case 18:
// 64-bit integer 18
writeInt64(ByteBuffer.wrap(data).getInt(), writer, fieldName, isList);
break;
default:
// In case of Object(3)/Binary data (5)/Object id (7) or in other case
// considering as VarBinary
final byte[] bytes = readBinaryData.getData();
writeBinary(writer, fieldName, isList, vb, bytes);
break;
}
}
Aggregations