if ((os instanceof ByteOutputStream) && lazyAttachments) {
((ByteOutputStream)os).write(in);
} else {
ByteOutputStream baos = new ByteOutputStream(in.available());
baos.write(in);
baos.writeTo(os);
// reset the inputstream so that we can support a
//getAttachment later
in = baos.newInputStream();
}