code: public byte[] toByteArray() {
          try {
              ByteArrayOutputStream bout = new ByteArrayOutputStream(size());
              pipe(bout);
              return bout.toByteArray();
          } catch (IOException ioe) {
              throw new RuntimeException("should be impossible", ioe);
          }
      }
docs: Gets a copy of the buffered bytes.
  
  @return the byte array
  @see org.bson.io.OutputBuffer#pipe(java.io.OutputStream)