[英]How to Remove all output from JTidy?
I'm using JTidy to clean up some XML, like this: 我正在使用JTidy清理一些XML,如下所示:
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. 如图所示这里 ,但也不能工作。
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). 最好使用某种Null输出流(显然,Apache Commons具有这种野兽)。 But the gist of it is the same.
但是要点是一样的。
Of course, that's a bit of a hack... 当然,这有点hack ...
Instead of tidy.setErrout(null);
代替
tidy.setErrout(null);
use tidy.setErrout(new PrintWriter(new ByteArrayOutputStream()));
使用
tidy.setErrout(new PrintWriter(new ByteArrayOutputStream()));
this seems to work for me. 这似乎对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.