XMLStreamWriter writer = createWriter(actualObject, actualClass, genericType, enc,
actualOs, isCollection);
ms.marshal(actualObject, writer);
writer.close();
if (os != actualOs) {
StringIndenter formatter = new StringIndenter(
IOUtils.newStringFromBytes(((CachedOutputStream)actualOs).getBytes()));
Writer outWriter = new OutputStreamWriter(os, enc);
IOUtils.copy(new StringReader(formatter.result()), outWriter, 2048);
outWriter.close();
}
}