Code example for ByteArrayOutputStream

Methods: toByteArray

0
        int size = encoder.writeObject(outputBuffer, lazyDBObj);
        assertEquals(lazyDBObj.getBSONSize(), size);
        assertEquals(lazyDBObj.getBSONSize(), outputBuffer.size());
 
        // this is just asserting that the encoder actually piped the correct bytes 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        lazyDBObj.pipe(baos);
        assertArrayEquals(baos.toByteArray(), outputBuffer.toByteArray());
    } 
 
    private DBObject createSimpleTestDoc() { 
        DBObject obj = new BasicDBObject("_id", new ObjectId());
        obj.put("first", 1);
        obj.put("second", "str1");
        obj.put("third", true);
        obj.put("fourth", new BasicDBObject("firstNested", 1));
        return obj;
    } 
 
 
    private DBObject createTestDoc() {