if (reader.markSupported())
reader.mark(Integer.MAX_VALUE);
PushbackReader pushbackReader = new PushbackReader(reader, 4096);
//some size to unread <?xml ....?>
XMLDeclarationParser ev =
new XMLDeclarationParser(pushbackReader);
try {
ev.parse();
} catch (Exception ex) {
throw new TransformerException(
"Unable to run the JAXP transformer on a stream "
+ ex.getMessage());
}
Writer writer =
new OutputStreamWriter(os /*, ev.getEncoding()*/);
ev.writeTo(writer); // doesn't write any, if no header
int num;
char[] ac = new char[8192];
while ((num = pushbackReader.read(ac)) != -1) {
writer.write(ac, 0, num);