String charset = options.getCharset();
if (charset == null) {
if (base instanceof Document)
charset = ((Document)base).getCharset();
else if (base instanceof Element) {
Document doc = ((Element)base).getDocument();
if (doc != null) charset = doc.getCharset();
}
if (charset == null) charset = "UTF-8";
} else {
Document doc = null;
if (base instanceof Document)
doc = (Document)base;
else if (base instanceof Element)
doc = ((Element)base).getDocument();
if (doc != null) doc.setCharset(charset);
}
base.writeTo(new OutputStreamWriter(out,charset));
finishCompressedOutputStream(out, options);
if (options.getAutoClose()) out.close();
}