public byte[] encode(BSONObject o) { BasicOutputBuffer buf = new BasicOutputBuffer(); set(buf); putObject(o); done(); return buf.toByteArray(); }
@Test public void testOBBig1() { BasicOutputBuffer a = new BasicOutputBuffer(); StringBuilder b = new StringBuilder(); for (String x : _data) { a.write(x.getBytes()); b.append(x); } assertEquals(a.asString(), b.toString()); }
@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()); }