本文整理汇总了Java中org.bson.types.Binary类的典型用法代码示例。如果您正苦于以下问题:Java Binary类的具体用法?Java Binary怎么用?Java Binary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Binary类属于org.bson.types包,在下文中一共展示了Binary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unmarshall
import org.bson.types.Binary; //导入依赖的package包/类
private RealVector unmarshall(Document doc, int limit) {
if (!metadata.isBinary()) {
throw new UnsupportedOperationException("Can't consume non-binary models.");
}
try {
final Binary binary = doc.get(VECTOR_FIELD_NAME, Binary.class);
final byte[] b = binary.getData();
if (metadata.getLoaderId().equalsIgnoreCase("legacy")) {
return BinaryCodecs.legacyUnmarshall(b, limit, metadata.isSparse(), metadata.getDimensions());
}
else {
return BinaryCodecs.unmarshall(b, metadata.isSparse(), metadata.getDimensions());
}
}
catch (Exception e) {
logger.error("Error unmarshalling vector", e);
}
return null;
}
示例2: getLobLiteral
import org.bson.types.Binary; //导入依赖的package包/类
public static Literal getLobLiteral(Object inputValue, String dataType, Connection connection) throws SQLException{
Literal literal = null;
if(connection==null){
literal = new NullLiteral();
}else{
if(SqlColumnType.BLOB.equalsIgnoreCase(dataType)){
literal= new BlobLiteral();
Blob blob = connection.createBlob();
Binary objArray = (Binary) inputValue;
blob.setBytes(1, objArray.getData());
literal.setLiteralValue(blob);
}else if(SqlColumnType.CLOB.equalsIgnoreCase(dataType)){
literal = new ClobLiteral();
Clob clob = connection.createClob();
clob.setString(1, String.valueOf(inputValue));
literal.setLiteralValue(clob);
}
}
return literal;
}
示例3: getObject
import org.bson.types.Binary; //导入依赖的package包/类
private BsonTest getObject() {
BsonTest bsonTest = new BsonTest();
bsonTest.setTestDouble(20.00);
bsonTest.setTestString("测试一下");
byte[] bytes = new byte[3];
bytes[0] = 3;
bytes[1] = 4;
bytes[2] = 1;
bsonTest.setTestBinary(new Binary(BsonBinarySubType.USER_DEFINED, bytes));
ArrayList<BsonTest> testArray = new ArrayList<BsonTest>();
BsonTest test1 = new BsonTest();
test1.setTestDouble(30.00);
testArray.add(test1);
bsonTest.setTestArray(testArray);
bsonTest.setBsonTest(test1);
bsonTest.setTestObjectId(new ObjectId());
bsonTest.setTestStringObjectId("59074307568fad36808ff0c5");
bsonTest.setTestBoolean(true);
bsonTest.setTestDate(new Date());
bsonTest.setTestNull(null);
bsonTest.setTestInt(2333);
bsonTest.setTestLong(2222L);
return bsonTest;
}
示例4: getObject
import org.bson.types.Binary; //导入依赖的package包/类
private BsonTest getObject() {
BsonTest bsonTest = new BsonTest();
bsonTest.setTestDouble(20.00);
bsonTest.setTestString("测试一下");
byte[] bytes = new byte[3];
bytes[0] = 3;
bytes[1] = 4;
bytes[2] = 1;
bsonTest.setTestBinary(new Binary(BsonBinarySubType.USER_DEFINED, bytes));
ArrayList<BsonTest> testArray = new ArrayList<BsonTest>();
BsonTest test1 = new BsonTest();
test1.setTestDouble(30.00);
testArray.add(test1);
bsonTest.setTestArray(testArray);
bsonTest.setBsonTest(test1);
ObjectId testObjectId = new ObjectId();
bsonTest.setTestObjectId(testObjectId);
bsonTest.setTestStringObjectId(testObjectId.toHexString());
bsonTest.setTestBoolean(true);
bsonTest.setTestDate(new Date());
bsonTest.setTestNull(null);
bsonTest.setTestInt(2333);
bsonTest.setTestLong(2222L);
return bsonTest;
}
示例5: setUp
import org.bson.types.Binary; //导入依赖的package包/类
@Before
public void setUp() {
tenant = tenantRepository.findByDomainName("konker");
application = applicationRepository.findByTenantAndName(tenant.getId(), "konker");
otherApplication = applicationRepository.findByTenantAndName(tenant.getId(), "smartffkonker");
deviceModel1 = DeviceModel.builder()
.tenant(tenant)
.application(application)
.name("air conditioner")
.guid("be68c474-b961-4974-829d-daeed9e4142b")
.build();
deviceModelRepository.save(deviceModel1);
DeviceFirmware deviceFirmware = DeviceFirmware.builder()
.tenant(tenant)
.application(application)
.deviceModel(deviceModel1)
.firmware(new Binary(firmwareBinary))
.uploadDate(Instant.now())
.version("0.1.0")
.build();
deviceFirmwareRepository.save(deviceFirmware);
}
示例6: shouldSave
import org.bson.types.Binary; //导入依赖的package包/类
@Test
public void shouldSave() {
DeviceFirmware newFirmware = DeviceFirmware.builder()
.tenant(tenant)
.application(application)
.deviceModel(deviceModel1)
.version("0.2.0")
.firmware(new Binary(firmwareBinary))
.build();
ServiceResponse<DeviceFirmware> response = subject.save(tenant, application, newFirmware);
assertThat(response, isResponseOk());
assertThat(response.getResult(), notNullValue());
DeviceFirmware firmwareFromDB = deviceFirmwareRepository.findUnique(tenant.getId(), application.getName(), deviceModel1.getId(), "0.2.0");
assertThat(firmwareFromDB.getVersion(), is("0.2.0"));
assertThat(firmwareFromDB.getFirmware().getData(), is(firmwareBinary));
assertThat(firmwareFromDB.getUploadDate(), notNullValue());
}
示例7: readBytes
import org.bson.types.Binary; //导入依赖的package包/类
@Override
public ByteBuffer readBytes(ByteBuffer old) throws IOException {
jumpToNextField();
try {
Object next = iteratorStack.peek().next();
if (next == null) {
return null;
} else if (next instanceof Binary) {
return ByteBuffer.wrap(((Binary) next).getData());
} else {
return ByteBuffer.wrap((byte[]) next);
}
} finally {
finishRead();
}
}
示例8: getDataType
import org.bson.types.Binary; //导入依赖的package包/类
private String getDataType(Object value) {
if (value instanceof Integer) {
return TypeFacility.RUNTIME_NAMES.INTEGER;
}
else if (value instanceof Double) {
return TypeFacility.RUNTIME_NAMES.DOUBLE;
}
else if (value instanceof Boolean) {
return TypeFacility.RUNTIME_NAMES.BOOLEAN;
}
else if (value instanceof Long) {
return TypeFacility.RUNTIME_NAMES.LONG;
}
else if (value instanceof String) {
return TypeFacility.RUNTIME_NAMES.STRING;
}
else if (value instanceof Date) {
return TypeFacility.RUNTIME_NAMES.TIMESTAMP;
}
else if (value instanceof Binary || value instanceof byte[]) {
return TypeFacility.RUNTIME_NAMES.VARBINARY;
}
else {
return TypeFacility.RUNTIME_NAMES.OBJECT;
}
}
示例9: testWithDocument
import org.bson.types.Binary; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testWithDocument() {
MongoDatabase db = connect();
BytePojo pojo = insert(db);
MongoCollection<Document> coll = db.getCollection(COLL_NAME);
Document doc = coll.find().first();
assertThat(doc).hasSize(8);
assertThat(doc.get("_id")).isEqualTo(pojo.getId());
assertThat(doc.get("scalarPrimitive")).isEqualTo((int) pojo.getScalarPrimitive());
assertThat(doc.get("scalar")).isEqualTo(pojo.getScalar().intValue());
assertThat(doc.get("arrayPrimitive"))
.isEqualTo(new Binary(new byte[] { 3, 4, 5 }));
assertThat(doc.get("array")).isEqualTo(new Binary(new byte[] { 6, 7, 8 }));
assertThat((List<Integer>) doc.get("list")).containsExactly(10, 11);
assertThat((List<Integer>) doc.get("set")).containsOnly(12, 13);
assertThat((Map<String, Integer>) doc.get("map")).containsOnly(
MapEntry.entry("one", 1), MapEntry.entry("two", 2),
MapEntry.entry("three", 3), MapEntry.entry("null", null));
}
示例10: fromDb
import org.bson.types.Binary; //导入依赖的package包/类
@Nullable
@Override
public byte[] fromDb(@Nullable final Object dbValue) throws MapperException {
if (dbValue == null) {
return null;
}
if (dbValue instanceof Binary) {
final Binary binary = (Binary) dbValue;
return binary.getData();
}
if (dbValue instanceof byte[]) {
final byte[] bytes = (byte[]) dbValue;
return bytes;
}
throw new MapperException("Bytes expected, " +
"got a value of type: " + dbValue.getClass().getCanonicalName());
}
示例11: shouldInsertOneDocumentWithBinaryData
import org.bson.types.Binary; //导入依赖的package包/类
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void shouldInsertOneDocumentWithBinaryData() throws IOException {
// given
final byte[] bytes = new byte[]{0,1,2,3,4,5,6,7,9};
final Foo foo = new FooBuilder().withStringField("jdoe").withPrimitiveIntField(42)
.withEnumFoo(EnumFoo.FOO).withBytes(bytes).build();
// when
fooCollection.add(foo);
// then
assertThat(foo.getId()).isNotNull();
assertThat(
getMongoClient().getDatabase(DATABASE_NAME).getCollection(getCollectionName()).count())
.isEqualTo(1);
final Document createdDoc = getMongoClient().getDatabase(DATABASE_NAME)
.getCollection(getCollectionName()).find().first();
final Binary retrievedBinaryContent = (Binary) createdDoc.get("raw_content");
assertThat(retrievedBinaryContent).isNotNull();
assertThat(retrievedBinaryContent.getData()).as("Check insertion of byte[]").isEqualTo(bytes);
}
示例12: shouldInsertDocumentWithBinaryField
import org.bson.types.Binary; //导入依赖的package包/类
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void shouldInsertDocumentWithBinaryField() throws IOException {
// given
// when
final Foo foo = new FooBuilder().withId(new ObjectId("54c28b0b0f2dacc85ede5286"))
.withBytes(new byte[]{1,2,3,4}).build();
fooCollection.add(foo);
// then
assertThat(
getMongoClient().getDatabase(DATABASE_NAME).getCollection(getCollectionName()).count())
.isEqualTo(1);
final Document createdDoc = getMongoClient().getDatabase(DATABASE_NAME)
.getCollection(getCollectionName()).find().first();
assertThat(createdDoc.get("raw_content")).isNotNull().isEqualTo(new Binary(new byte[]{1,2,3,4}));
final Foo foundFoo = fooCollection.all().first();
assertThat(foundFoo.getBytes()).isNotNull().isEqualTo(new byte[]{1,2,3,4});
}
示例13: SnapImag
import org.bson.types.Binary; //导入依赖的package包/类
public SnapImag(Object snapId, String url, BufferedImage imag) {
_dbo = new BasicDBObject();
_dbo.put(_idField, snapId);
_dbo.put(_urlField, url);
_dbo.put(_widthField, imag.getWidth());
_dbo.put(_heightField, imag.getHeight());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(imag, "jpg", baos);
baos.flush();
} catch (IOException e) {
throw new IllegalStateException("Could not serialize image", e);
}
byte[] bytes = baos.toByteArray();
_dbo.put(_bytesField, new Binary(bytes));
}
示例14: findAliveStatus
import org.bson.types.Binary; //导入依赖的package包/类
public final static AliveStatus findAliveStatus(
DBCollection coll,
byte[] id,
Date now) {
BasicDBObject q = new BasicDBObject();
q.put(_idField, new Binary(id));
BasicDBObject f = new BasicDBObject();
f.put(_dyingDateField, 1);
f.put(_deadDateField, 1);
DBObject dbo = coll.findOne(q, f);
if (dbo != null) {
SummResult result = new SummResult(dbo);
return result.getAliveStatus(now);
} else { // not found at all
return AliveStatus.Dead;
}
}
示例15: SnapThumb
import org.bson.types.Binary; //导入依赖的package包/类
public SnapThumb(Object snapId, int kindId, BufferedImage imag) {
_dbo = new BasicDBObject();
_dbo.put(_snapIdField, snapId);
_dbo.put(_kindIdField, kindId);
_dbo.put(_widthField, imag.getWidth());
_dbo.put(_heightField, imag.getHeight());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(imag, "jpg", baos);
baos.flush();
} catch (IOException e) {
throw new IllegalStateException("Could not serialize image", e);
}
byte[] bytes = baos.toByteArray();
_dbo.put(_bytesField, new Binary(bytes));
}