Adam Sikora
Adam Sikora

Reputation: 3

Redirecting output stream to SAX parser

A third party method outputs XML to terminal. How can I redirect it to a stream readable by SAX parser? I am trying something like this:

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);

However, since the last line does not work, I was hoping for something like this:

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

Upvotes: 0

Views: 330

Answers (1)

kumesana
kumesana

Reputation: 2490

InputStream xmlInput = new ByteArrayInputStream(baos.toByteArray());

Upvotes: 1

Related Questions