private OutputStream wrapOutput(Object output) {
if(output instanceof OutputStream) {
return (OutputStream)output;
} else if(output instanceof ImageOutputStream){
return new OutputStreamWrapper((ImageOutputStream) output);
} else {
throw new UnsupportedOperationException(output.getClass().getName());
}
}