Esempio n. 1
0
 /**
  * {@inheritDoc}
  *
  * @see Writable#readFields(DataInput)
  */
 public void readFields(DataInput in) throws IOException {
   BSONDecoder dec = new BSONDecoder();
   BSONCallback cb = new BasicBSONCallback();
   // Read the BSON length from the start of the record
   int dataLen = in.readInt();
   byte[] buf = new byte[dataLen];
   in.readFully(buf);
   dec.decode(buf, cb);
   _doc = (BSONObject) cb.get();
   log.info("Decoded a BSON Object: " + _doc);
 }
Esempio n. 2
0
  void _test(BSONObject o, int size, String hash) throws IOException {
    BSONEncoder e = new BSONEncoder();
    OutputBuffer buf = new BasicOutputBuffer();
    e.set(buf);
    e.putObject(o);
    assertEquals(size, buf.size());
    assertEquals(hash, buf.md5());
    e.done();

    BSONDecoder d = new BSONDecoder();
    BasicBSONCallback cb = new BasicBSONCallback();
    int s = d.decode(new ByteArrayInputStream(buf.toByteArray()), cb);
    assertEquals(size, s);

    OutputBuffer buf2 = new BasicOutputBuffer();
    e.set(buf2);
    e.putObject((BSONObject) cb.get());
    assertEquals(size, buf2.size());
    assertEquals(hash, buf2.md5());
  }