Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

outputstream to inputstream

Fri Oct 24, 2008 8:48 pm

Hi everyone,
What i am trying to do is to parse some xml being returned to me with
the following code:

DocumentBuilderFactory xmlResults = DocumentBuilderFactory.newInstanc();
DocumentBuilder docBuilder =xmlResults.newDocumentBuilder();
Document iterDoc = docBuilder.parse(in);

The xml is coming back to me as an outputstream though.right now i am
trying to get the outputstream from the HTTPUrlConnection by using
the .getOutputStream method. I then need to take this and convert it
into and inputstream so i can pass it to docBuilder.parse...I am having
problems following the websites that i have found...

I know i need to define a byte array
something like:ByteArrayOutputStream out = new ByteArrayOutputStream();
or would i want to use a regular byte array??

After i do this how to i take the output stream and store it in the
array then convert it to a inputstream



Re: outputstream to inputstream

Fri Oct 24, 2008 8:49 pm

have you tried to do something like this?:

Code:
DocumentBuilderFactory xmlResults = DocumentBuilderFactory.newInstanc();
DocumentBuilder docBuilder =xmlResults.newDocumentBuilder();
ByteArrayInputStream bais = new ByteArrayInputStream(out.toByteArray());
docBuilder.parse(new InputSource(bais));
Document dom = docBuilder.getDocument();


I think you can convert the OutputStream to an ByteArrayInputStream
and after that use it to "parse" the XML.

Post a reply
  Related Posts  to : outputstream to inputstream
 Convert outputstream to inputstream     -  

Topic Tags

Java Files and I/O