Java 类org.bson.BasicBSONDecoder 实例源码

项目:Camel    文件:MongoDbBasicConverters.java   
@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;
}
项目:if26_projet    文件:ServletUtils.java   
/**
 * 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();
}
项目:mongo-deep-mapreduce    文件:Record.java   
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;
}
项目:mongodb-async-performance    文件:BsonPerformanceITest.java   
/**
 * 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);
}
项目:azkaban    文件:BsonFileViewer.java   
@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();
    }
}
项目:azkaban-plugins    文件:BsonFileViewer.java   
@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();
  }
}
项目:usergrid    文件:BSONUtils.java   
@Override
protected BSONDecoder initialValue() {
    return new BasicBSONDecoder();
}