本文整理汇总了Java中org.bson.BasicBSONDecoder类的典型用法代码示例。如果您正苦于以下问题:Java BasicBSONDecoder类的具体用法?Java BasicBSONDecoder怎么用?Java BasicBSONDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BasicBSONDecoder类属于org.bson包,在下文中一共展示了BasicBSONDecoder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: fromInputStreamToDBObject
import org.bson.BasicBSONDecoder; //导入依赖的package包/类
@Converter
public static BasicDBObject fromInputStreamToDBObject(InputStream is, Exchange exchange) {
BasicDBObject answer = null;
try {
byte[] input = IOConverter.toBytes(is);
if (isBson(input)) {
BSONCallback callback = new JSONCallback();
new BasicBSONDecoder().decode(input, callback);
answer = (BasicDBObject) callback.get();
} else {
answer = (BasicDBObject) JSON.parse(IOConverter.toString(input, exchange));
}
} catch (Exception e) {
LOG.warn("String -> DBObject conversion selected, but the following exception occurred. Returning null.", e);
} finally {
// we need to make sure to close the input stream
IOHelper.close(is, "InputStream", LOG);
}
return answer;
}
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MongoDbBasicConverters.java
示例2: decryptBSON
import org.bson.BasicBSONDecoder; //导入依赖的package包/类
/**
* decrypt a BSON string
* @param datas : BSON formated String
* @return JSON formated String
*/
private static String decryptBSON(String datas){
String[] tab = datas.split("[a-zA-Z]");
byte[] array = new byte[tab.length];
for(int i =0; i<tab.length; i++){
array[i] = Byte.valueOf(tab[i]);
}
BSONDecoder decoder = new BasicBSONDecoder();
BasicBSONObject obj = (BasicBSONObject) decoder.readObject(array);
System.out.println(obj);
return obj.toString();
}
开发者ID:steven89,项目名称:if26_projet,代码行数:17,代码来源:ServletUtils.java
示例3: getContent
import org.bson.BasicBSONDecoder; //导入依赖的package包/类
public BSONObject getContent(FileSystem fs) {
if (cache != null)
return cache;
byte[] extentBuffer = extent.getBuffer(fs);
byte[] buff = new byte[BSONlength];
for (int i = offset + 16; i < offset + 16 + BSONlength; i++)
buff[i - offset - 16] = extentBuffer[i];
BasicBSONDecoder decoder = new BasicBSONDecoder();
cache = decoder.readObject(buff);
return cache;
}
开发者ID:groupon,项目名称:mongo-deep-mapreduce,代码行数:15,代码来源:Record.java
示例4: doLegacyRead
import org.bson.BasicBSONDecoder; //导入依赖的package包/类
/**
* Reads documents via a {@link BasicBSONDecoder}.
*
* @param bytes
* The bytes of the document to be read.
* @param divisor
* The divisor for the number of {@link #ITERATIONS}.
* @return The time to read each document in microseconds.
* @see #testLargeDocumentReadPerformance()
*/
protected double doLegacyRead(final byte[] bytes, final int divisor) {
final BasicBSONDecoder decoder = new BasicBSONDecoder();
final int iterations = ITERATIONS / divisor;
final long startTime = System.nanoTime();
for (int i = 0; i < iterations; ++i) {
decoder.readObject(bytes);
}
final long endTime = System.nanoTime();
final double delta = ((double) (endTime - startTime))
/ TimeUnit.MICROSECONDS.toNanos(1);
return (delta / iterations);
}
开发者ID:allanbank,项目名称:mongodb-async-performance,代码行数:25,代码来源:BsonPerformanceITest.java
示例5: displayFile
import org.bson.BasicBSONDecoder; //导入依赖的package包/类
@Override
public void displayFile(
FileSystem fs,
Path path,
OutputStream outStream,
int startLine,
int endLine) throws IOException {
FSDataInputStream in = null;
try {
in = fs.open(path, 16 * 1024 * 1024);
long endTime = System.currentTimeMillis() + STOP_TIME;
BasicBSONCallback callback = new BasicBSONCallback();
BasicBSONDecoder decoder = new BasicBSONDecoder();
/*
* keep reading and rendering bsonObjects until one of these conditions is met:
*
* a. we have rendered all bsonObjects desired.
* b. we have run out of time.
*/
for (int lineno = 1; lineno <= endLine && System.currentTimeMillis() <= endTime; lineno++) {
if (lineno < startLine) {
continue;
}
callback.reset();
decoder.decode(in, callback);
BSONObject value = (BSONObject) callback.get();
StringBuilder bldr = new StringBuilder();
bldr.append("\n\n Record ");
bldr.append(lineno);
bldr.append('\n');
JSON.serialize(value, bldr);
outStream.write(bldr.toString().getBytes("UTF-8"));
}
}
catch (IOException e) {
outStream.write(("Error in display avro file: " + e.getLocalizedMessage()).getBytes("UTF-8"));
}
finally {
if (in != null) {
in.close();
}
outStream.flush();
}
}
开发者ID:JasonBian,项目名称:azkaban,代码行数:52,代码来源:BsonFileViewer.java
示例6: displayFile
import org.bson.BasicBSONDecoder; //导入依赖的package包/类
@Override
public void displayFile(FileSystem fs, Path path, OutputStream outStream,
int startLine, int endLine) throws IOException {
FSDataInputStream in = null;
try {
in = fs.open(path, 16 * 1024 * 1024);
long endTime = System.currentTimeMillis() + STOP_TIME;
BasicBSONCallback callback = new BasicBSONCallback();
BasicBSONDecoder decoder = new BasicBSONDecoder();
/*
* keep reading and rendering bsonObjects until one of these conditions is
* met:
*
* a. we have rendered all bsonObjects desired. b. we have run out of
* time.
*/
for (int lineno = 1; lineno <= endLine
&& System.currentTimeMillis() <= endTime; lineno++) {
if (lineno < startLine) {
continue;
}
callback.reset();
decoder.decode(in, callback);
BSONObject value = (BSONObject) callback.get();
StringBuilder bldr = new StringBuilder();
bldr.append("\n\n Record ");
bldr.append(lineno);
bldr.append('\n');
JSON.serialize(value, bldr);
outStream.write(bldr.toString().getBytes("UTF-8"));
}
} catch (IOException e) {
outStream
.write(("Error in display avro file: " + e.getLocalizedMessage())
.getBytes("UTF-8"));
} finally {
if (in != null) {
in.close();
}
outStream.flush();
}
}
开发者ID:azkaban,项目名称:azkaban-plugins,代码行数:50,代码来源:BsonFileViewer.java
示例7: initialValue
import org.bson.BasicBSONDecoder; //导入依赖的package包/类
@Override
protected BSONDecoder initialValue() {
return new BasicBSONDecoder();
}
开发者ID:apache,项目名称:usergrid,代码行数:5,代码来源:BSONUtils.java
注:本文中的org.bson.BasicBSONDecoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论