Пример #1
0
 /**
  * {@inheritDoc}
  *
  * @see Writable#write(DataOutput)
  */
 public void write(DataOutput out) throws IOException {
   BSONEncoder enc = new BSONEncoder();
   BasicOutputBuffer buf = new BasicOutputBuffer();
   enc.set(buf);
   enc.putObject(_doc);
   enc.done();
   out.writeInt(buf.size());
   // For better performance we can copy BasicOutputBuffer.pipe(OutputStream)
   // to have a method signature that works with DataOutput
   out.write(buf.toByteArray());
 }
Пример #2
0
  @Test
  public void testOB1() {
    BasicOutputBuffer buf = new BasicOutputBuffer();
    buf.write("eliot".getBytes());
    assertEquals(5, buf.getPosition());
    assertEquals(5, buf.size());

    assertEquals("eliot", buf.asString());

    buf.setPosition(2);
    buf.write("z".getBytes());
    assertEquals("elzot", buf.asString());

    buf.seekEnd();
    buf.write("foo".getBytes());
    assertEquals("elzotfoo", buf.asString());

    buf.seekStart();
    buf.write("bar".getBytes());
    assertEquals("barotfoo", buf.asString());
  }