本文整理了Java中org.bson.BSON.encode()
方法的一些代码示例,展示了BSON.encode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BSON.encode()
方法的具体详情如下:
包路径:org.bson.BSON
类名称:BSON
方法名:encode
[英]Encodes a DBObject as a BSON byte array.
[中]将DBObject编码为BSON字节数组。
代码示例来源:origin: com.sequoiadb/sequoiadb-driver
public static byte[] encodeBSONObj(BSONObject obj) {
return BSON.encode(obj);
}
代码示例来源:origin: thiloplanz/jmockmongo
/**
* BSON objects are considered equal when their binary encoding matches
*/
static boolean equals(BSONObject a, BSONObject b) {
return a.keySet().equals(b.keySet())
&& Arrays.equals(BSON.encode(a), BSON.encode(b));
}
代码示例来源:origin: luxdelux/redpack
public byte[] packResponse(RPCResponse response) throws PackException, IOException {
return BSON.encode(response.getBSONObject());
}
代码示例来源:origin: de.bwaldvogel/mongo-java-server-test-common
private void writeBson(OutputStream outputStream, Document data) throws Exception {
outputStream.write(BSON.encode(new BasicBSONObject(data)));
}
代码示例来源:origin: luxdelux/redpack
public byte[] packRequest(RPCRequest request) {
return BSON.encode(request.getBSONObject());
}
代码示例来源:origin: kakaochatfriend/KakaoChatFriendAPI
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object obj) throws Exception {
ChannelBuffer buffer = null;
// null 인경우에는 DownStream으로 전달이 안됨
if ( !( obj instanceof BSONObject ) ) {
LOG.warn ("obj isn't BSONObject, "+obj);
return null;
}
BSONObject bsonOut = (BSONObject) obj;
byte[] baOut = null;
try {
buffer = ChannelBuffers.dynamicBuffer();
baOut = BSON.encode(bsonOut);
buffer.writeBytes( baOut );
}catch (Exception e) {
LOG.warn("exception occurred by"+obj, e);
}
return buffer;
}
代码示例来源:origin: ttrelle/spring-data-examples
private static void bsonize(DBObject doc) {
final byte[] buff = BSON.encode(doc);
println( toString(buff) );
}
代码示例来源:origin: kakaochatfriend/KakaoChatFriendAPI
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
if (msg instanceof byte[]) {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes((byte[]) msg);
return buffer;
} else if (msg instanceof BSONObject) {
System.out.println("encode:BSONObject");
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(BSON.encode((BSONObject) msg));
return buffer;
} else {
System.out.println(this.getClass().getName() + " : unknown type." + msg);
}
return null;
}
代码示例来源:origin: com.wordnik/mongo-admin-utils
public void processRecord(String collectionName, BasicDBObject dbo) throws Exception {
if(WRITE_JSON){
RotatingFileWriter writer = (RotatingFileWriter)WRITERS.get(collectionName);
if(writer == null){
writer = new RotatingFileWriter(collectionName, OUTPUT_DIRECTORY, "json", UNCOMPRESSED_FILE_SIZE_MB * 1048576L, COMPRESS_OUTPUT_FILES);
WRITERS.put(collectionName, writer);
}
writer.write(dbo.toString());
}
else{
BinaryRotatingFileWriter writer = (BinaryRotatingFileWriter)WRITERS.get(collectionName);
if(writer == null){
writer = new BinaryRotatingFileWriter(collectionName, OUTPUT_DIRECTORY, "bson", UNCOMPRESSED_FILE_SIZE_MB * 1048576L, COMPRESS_OUTPUT_FILES);
WRITERS.put(collectionName, writer);
}
writer.write(BSON.encode(dbo));
}
}
代码示例来源:origin: com.wordnik/mongo-admin-utils
@Override
public void processRecord(BasicDBObject dbo) throws Exception {
if(WRITE_JSON){
RotatingFileWriter writer = (RotatingFileWriter)WRITERS.get(collectionName);
if(writer == null){
writer = new RotatingFileWriter(collectionName, outputDirectory, "json", UNCOMPRESSED_FILE_SIZE_MB * 1048576L, COMPRESS_OUTPUT_FILES);
WRITERS.put(collectionName, writer);
}
writer.write(dbo.toString());
}
else{
BinaryRotatingFileWriter writer = (BinaryRotatingFileWriter)WRITERS.get(collectionName);
if(writer == null){
writer = new BinaryRotatingFileWriter(collectionName, outputDirectory, "bson", UNCOMPRESSED_FILE_SIZE_MB * 1048576L, COMPRESS_OUTPUT_FILES);
WRITERS.put(collectionName, writer);
}
writer.write(BSON.encode(dbo));
}
}
代码示例来源:origin: kakaochatfriend/KakaoChatFriendAPI
bsonOut.put("message", DATA_NOT_FOUND_MSG);
e.getChannel().write(BSON.encode(bsonOut));
bOut.put("message", WELCOME_MSG);
e.getChannel().write(BSON.encode(bOut));
} else if (type.equals("ping")) {
BSONObject bOut = new BasicBSONObject();
bOut.put("type", "pong");
bOut.put("time", (Long)bsonIn.get("time"));
e.getChannel().write(BSON.encode(bOut));
代码示例来源:origin: lumongo/lumongo
@Override
public Lumongo.ResultDocument getSourceDocument(String uniqueId, FetchType fetchType) throws Exception {
if (!FetchType.NONE.equals(fetchType)) {
MongoDatabase db = mongoClient.getDatabase(database);
MongoCollection<Document> coll = db.getCollection(rawCollectionName);
Document search = new Document(MongoConstants.StandardFields._ID, uniqueId);
Document result = coll.find(search).first();
if (null != result) {
long timestamp = (long) result.remove(TIMESTAMP);
ResultDocument.Builder dBuilder = ResultDocument.newBuilder();
dBuilder.setUniqueId(uniqueId);
dBuilder.setTimestamp(timestamp);
if (result.containsKey(METADATA)) {
Document metadata = (Document) result.remove(METADATA);
for (String key : metadata.keySet()) {
dBuilder.addMetadata(Metadata.newBuilder().setKey(key).setValue((String) metadata.get(key)));
}
}
if (FetchType.FULL.equals(fetchType)) {
BasicDBObject resultObj = new BasicDBObject();
resultObj.putAll(result);
ByteString document = ByteString.copyFrom(BSON.encode(resultObj));
dBuilder.setDocument(document);
}
dBuilder.setIndexName(indexName);
return dBuilder.build();
}
}
return null;
}
代码示例来源:origin: thiloplanz/jmockmongo
static ReplyMessage reply(Message request, int responseFlags,
long cursorId, int startingFrom, BSONObject... docs) {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
writeInt(buffer, responseFlags);
writeLong(buffer, cursorId);
writeInt(buffer, startingFrom);
writeInt(buffer, docs.length);
for (BSONObject doc : docs)
buffer.writeBytes(BSON.encode(doc));
ChannelBuffer header = ChannelBuffers.buffer(16);
outputMessageHeader(header, buffer.readableBytes() + 16, 1, request
.getRequestId(), OP_CODE_REPLY);
return new ReplyMessage(ChannelBuffers.wrappedBuffer(header, buffer));
}
}
内容来源于网络,如有侵权,请联系作者删除!