将输出流重定向到 SAX 解析器

Redirecting output stream to SAX parser

第三方方法输出XML到终端。如何将它重定向到 SAX 解析器可读的流?我正在尝试这样的事情:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
System.setOut(ps);
client.response(); //prints to terminal
System.out.flush();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();

... define handler ...

saxParser.parse(baos,handler);

但是,由于最后一行不起作用,我希望是这样的:

InputStream xmlInput = new InputStream(baos);
saxParser.parse(xmlInput,handler);
InputStream xmlInput = new ByteArrayInputStream(baos.toByteArray());