public static WriteOnCloseOutputStream createCachedStream(Message message, OutputStream os) {
// We need to ensure that we have an output stream which won't start writing the
// message until we have a chance to send a createsequence
if (!(os instanceof WriteOnCloseOutputStream)) {
WriteOnCloseOutputStream cached = new WriteOnCloseOutputStream(os);
message.setContent(OutputStream.class, cached);
os = cached;
}
return (WriteOnCloseOutputStream) os;
}