I would like to read in the XML response and make a temporary in-memory file from xml. Then I would like to read in the file to see if certain elements exist. After that, I just want to get rid of the temp file. I am familiar with creating and reading files to / from the file system, is it possible not to write, and then read from a file only in memory?
Why are you trying to create it as a βfileβ in memory? Just save it as an XML representation (whether using the JDOM, WOM or DOM API).
, "" . , , , , , !
? .
, , ByteArrayOutputStream ByteArrayInputStream //. , ; , , , , .
ByteArrayOutputStream
ByteArrayInputStream
ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer w = new OutputStreamWriter(baos); w.write(...); byte[] bytes = baos.toByteArray();
, ByteBuffer , .
ByteBuffer
, , , .
I do not see the need to create a temporary file just to check for the presence of certain elements. Most XML parsers let you read directly from some input stream. All you need to do is convert the XML response string to the input stream, and then pass it to some XML parser to perform validation: -
// converting string to input stream InputStream is = new ByteArrayInputStream( myString.getBytes( charset ) );