2

I'm using JTidy to clean up some XML, like this:

Tidy tidy = new Tidy();
tidy.setXmlOut(true);
tidy.setShowWarnings(false);
tidy.parse(new FileInputStream(strStrippedHTMLPath), new FileOutputStream(strXMLPath));

The problem is that it always outputs the following:

InputStream: Document content looks like HTML 4.01
5 warnings, no errors were found!

How can I prevent it from outputting anything? I tried:

tidy.setShowErrors(0);
tidy.setQuiet(true);
tidy.setErrout(null);

, as shown here, but that didn't work either.

Community
  • 1
  • 1
sudo
  • 319
  • 2
  • 4
  • 10

2 Answers2

1

Well, there's always:

PrintStream oldErr = System.err();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream newErr = new PrintStream(boas);
System.setErr(newErr);
tidy.parse(...);
System.setErr(oldErr);

It would be better to use some kind of Null output stream (apparently Apache Commons has such a beast). But the gist of it is the same.

Of course, that's a bit of a hack...

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
  • Just a quick warning: This is not thread safe and will redirect the error output for everything running in the VM, so be sure you know what you're doing! – FRotthowe Oct 10 '17 at 06:35
1

Instead of tidy.setErrout(null); use tidy.setErrout(new PrintWriter(new ByteArrayOutputStream())); this seems to work for me.

FRotthowe
  • 3,662
  • 25
  • 31