当前位置: 首页>>代码示例>>Java>>正文


Java BsonBinary类代码示例

本文整理汇总了Java中org.bson.BsonBinary的典型用法代码示例。如果您正苦于以下问题:Java BsonBinary类的具体用法?Java BsonBinary怎么用?Java BsonBinary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BsonBinary类属于org.bson包,在下文中一共展示了BsonBinary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertBinaryUUID

import org.bson.BsonBinary; //导入依赖的package包/类
/**
 * Converts a binary uuid to a standard uuid
 *
 * @param json The json string (should contain "$binary" and "$type" or something like that)
 * @return The uuid
 */
private UUID convertBinaryUUID(String key, String json) {
    BsonDocument document = BsonDocument.parse(json);

    BsonValue value = document.get(key);
    if(!(value instanceof BsonBinary)) {
        return null;
    }
    byte[] bytes = ((BsonBinary) value).getData();
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    long l1 = bb.getLong();
    long l2 = bb.getLong();

    return new UUID(l1, l2);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:22,代码来源:DbFilter.java

示例2: getBsonDocument

import org.bson.BsonBinary; //导入依赖的package包/类
public static BsonDocument getBsonDocument() {
    BsonDocument bsonObj = new BsonDocument().append("testDouble", new BsonDouble(20.777));
    List<BsonDocument> list = new ArrayList<BsonDocument>();
    list.add(bsonObj);
    list.add(bsonObj);
    byte[] bytes = new byte[3];
    bytes[0] = 3;
    bytes[1] = 2;
    bytes[2] = 1;
    BsonDocument bsonDocument = new BsonDocument().append("testDouble", new BsonDouble(20.99))
            .append("testString", new BsonString("testStringV"))
            .append("testArray", new BsonArray(list));
    return new BsonDocument().append("testDouble", new BsonDouble(20.99))
            .append("testString", new BsonString("testStringV"))
            .append("testArray", new BsonArray(list))
            .append("bson_test", bsonDocument)
            .append("testBinary", new BsonBinary(bytes))
            .append("testBsonUndefined", new BsonUndefined())
            .append("testObjectId", new BsonObjectId())
            .append("testStringObjectId", new BsonObjectId())
            .append("testBoolean", new BsonBoolean(true))
            .append("testDate", new BsonDateTime(time))
            .append("testNull", new BsonNull())
            .append("testInt", new BsonInt32(233))
            .append("testLong", new BsonInt64(233332));
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:27,代码来源:TestUtil.java

示例3: BsonCodecGenerator

import org.bson.BsonBinary; //导入依赖的package包/类
public BsonCodecGenerator(Models models) {
    this.models = models;
    Elements elems = models.getElemsUtil();
    // Reusable things for multiple types
    objectIdTypeMirror = elems.getTypeElement(ObjectId.class.getCanonicalName()).asType();
    bsonBinaryTypeMirror = elems.getTypeElement(BsonBinary.class.getCanonicalName()).asType();
    dateTypeMirror = elems.getTypeElement(Date.class.getCanonicalName()).asType();
    instantTypeMirror = elems.getTypeElement(Instant.class.getCanonicalName()).asType();
    stringTypeMirror = elems.getTypeElement(String.class.getCanonicalName()).asType();
    longTypeMirror = elems.getTypeElement(Long.class.getCanonicalName()).asType();
    classClassName = ClassName.get(Class.class);
    bsonWriterParamSpec = ParameterSpec.builder(BsonWriter.class, "writer").addModifiers(Modifier.FINAL).build();
    bsonReaderParamSpec = ParameterSpec.builder(BsonReader.class, "reader").addModifiers(Modifier.FINAL).build();
    encoderCtxParamSpec = ParameterSpec.builder(EncoderContext.class, "ctx").addModifiers(Modifier.FINAL).build();
    decoderCtxParamSpec = ParameterSpec.builder(DecoderContext.class, "ctx").addModifiers(Modifier.FINAL).build();
}
 
开发者ID:egopulse,项目名称:java-code-gen,代码行数:17,代码来源:BsonCodecGenerator.java

示例4: addEncodeStatements

import org.bson.BsonBinary; //导入依赖的package包/类
@Override
public void addEncodeStatements(TypeMirror type, CodeGeneratorContext ctx) {
	MethodSpec.Builder builder = ctx.builder();

	if (type.getKind() == TypeKind.BYTE) {
		builder.addStatement("writer.writeBinaryData(new $T($L))", BsonBinary.class,
				ctx.getter());
	}
	else {
		builder.addStatement("$T[] bw = $L", Byte.class, ctx.getter())
				.addStatement("byte[] b = new byte[bw.length]")
				.beginControlFlow("for (int i = 0; i < bw.length; i++)")
				.addStatement("b[i] = bw[i]").endControlFlow()
				.addStatement("writer.writeBinaryData(new $T(b))", BsonBinary.class);
	}
}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:17,代码来源:ByteArrayDelegate.java

示例5: encode

import org.bson.BsonBinary; //导入依赖的package包/类
@Override
public void encode(BsonWriter writer, FileUploader value, EncoderContext encoderContext) {
	writer.writeStartDocument();
	ObjectId objectId = new ObjectId();
	value.setOid(objectId.toString());

	writer.writeObjectId("_id", objectId);
	writer.writeBinaryData("file", new BsonBinary(value.getFile()));

	writer.writeEndDocument();
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:12,代码来源:FileUploaderCodec.java

示例6: encode

import org.bson.BsonBinary; //导入依赖的package包/类
@Override
protected BsonBinary encode(Collection<Byte> value) {
	final byte[] data = new byte[value.size()];
	final Iterator<Byte> iterator = value.iterator();
	int i = 0;
	while(iterator.hasNext()) {
		data[i++] = iterator.next();
	}
	return new BsonBinary(data);
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:11,代码来源:ByteCollectionCodec.java

示例7: decode

import org.bson.BsonBinary; //导入依赖的package包/类
@Override
protected Collection<Byte> decode(BsonBinary bsonValue) {
	final Collection<Byte> value = getInstance();
	for(byte bsonByte : bsonValue.getData()) {
		value.add(bsonByte);
	}
	return value;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:ByteCollectionCodec.java

示例8: primitiveByteArraySupport

import org.bson.BsonBinary; //导入依赖的package包/类
@Test
public void primitiveByteArraySupport() {
	final byte[] value = new byte[1024];
	new Random().nextBytes(value);
	final BsonBinary bsonValue = new BsonBinary(value);
	testSupport(value, bsonValue, byte[].class);
	assertArrayEquals(value, parser.fromBson(bsonValue, byte[].class, null));
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:ByteParserTest.java

示例9: genericByteArraySupport

import org.bson.BsonBinary; //导入依赖的package包/类
@Test
public void genericByteArraySupport() {
	final byte[] value = new byte[1024];
	new Random().nextBytes(value);
	final BsonBinary bsonValue = new BsonBinary(value);
	testSupport(ArrayUtils.toObject(value), bsonValue, Byte[].class);
	assertArrayEquals(ArrayUtils.toObject(value), parser.fromBson(bsonValue, Byte[].class, null));
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:ByteParserTest.java

示例10: serializeToBson_ShouldSerializePrimitiveByteArray_Successfully

import org.bson.BsonBinary; //导入依赖的package包/类
@Test
public void serializeToBson_ShouldSerializePrimitiveByteArray_Successfully() {
    byte[] bytes = "a byte array".getBytes();
    BsonValue bsonValue = this.parser.serializeToBson(bytes, null);
    byte[] data = ((BsonBinary) bsonValue).getData();
    assertEquals(bytes, data);
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:8,代码来源:ByteParserTest.java

示例11: serializeToBson_ShouldSerializeWrapperByteArray_Successfully

import org.bson.BsonBinary; //导入依赖的package包/类
@Test
public void serializeToBson_ShouldSerializeWrapperByteArray_Successfully() {
    byte[] bytes = "a byte array".getBytes();
    Byte[] wrappedBytes = ArrayUtils.toObject(bytes);
    BsonValue bsonValue = this.parser.serializeToBson(wrappedBytes, null);
    byte[] data = ((BsonBinary) bsonValue).getData();
    assertArrayEquals(bytes, data);
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:ByteParserTest.java

示例12: parseHexDocument

import org.bson.BsonBinary; //导入依赖的package包/类
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;
}
 
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:8,代码来源:GridFSTest.java

示例13: valueBinary

import org.bson.BsonBinary; //导入依赖的package包/类
public void valueBinary(byte[] data) {
  delegate.writeBinaryData(new BsonBinary(data));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:BsonWriter.java

示例14: decode

import org.bson.BsonBinary; //导入依赖的package包/类
@Override
public Binary decode(BsonValue bsonValue) {
    BsonBinary bsonBinary = bsonValue.asBinary();
    return new Binary(bsonBinary.getType(), bsonBinary.getData());
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:6,代码来源:BsonBinaryConverter.java

示例15: encode

import org.bson.BsonBinary; //导入依赖的package包/类
@Override
public BsonBinary encode(Binary object) {
    return new BsonBinary(object.getType(), object.getData());
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:5,代码来源:BsonBinaryConverter.java


注:本文中的org.bson.BsonBinary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。