@Override
  public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
    ByteArrayComposer w = new ByteArrayComposer();
    w.setCharset(useCharset);

    if (Collection.class.isInstance(graph)) {
      w.startTransmission();
      //            writeOptions(stream, w);
      toStream(w, stream);
      for (Object o : (Collection) graph) {
        w.writeRecord((BonaCustom) o);
        toStream(w, stream);
      }
      w.terminateTransmission();
      toStream(w, stream);
    } else {
      // assume single record
      w.writeRecord((BonaCustom) graph);
      toStream(w, stream);
    }
  }
 private void toStream(ByteArrayComposer w, OutputStream stream) throws IOException {
   stream.write(w.getBuffer(), 0, w.getLength());
   w.reset();
 }