Copy FileOutputStream to New FileInputStream

Discussions

Web tier: servlets, JSP, Web frameworks: Copy FileOutputStream to New FileInputStream

  1. Copy FileOutputStream to New FileInputStream (2 messages)

    (I'm cross-posting this from the J2EE General forum. Not sure of the best place to post this question.)

    We have a requirement for our users to be able to upload multiple xml files to our server for processing into our database. For security reasons, our network team does not want any files written to the servers (or any place accessible by the servers). Therefore, we are trying to work with the zipped files strictly within memory, without writing a physical file.

    The problem is this:
    The zip files exists in memory. The xml files have been unzipped into memory. But, after being unzipped, they exist in an output stream which can't be read (output streams are only for writing, right?). Therefore, to continue working with the xml (performing schema validations and loading into tables) they need to be in an input stream. We have not been able to find a way to convert an output stream into a new input stream.

    Can anyone suggest a way to resolve this? Can we perform schema validations and load to tables from the output stream? I don't believe so. It is my understanding that you can only write from an output stream, and not read from it.
  2. Jakarta Commons IO - IOUtils[ Go to top ]

    Jakarta Commons IO - IOUtils should have something that you can use:
    http://jakarta.apache.org/commons/io/apidocs/org/apache/commons/io/IOUtils.html
  3. You could simply use the ByteArrayOutputStream or StringWriter to receive the data.

    Then receive the byte array / string from the result and use that as the data for an input stream (ByteArrayInputStream / StringReader / StringBufferInputStream / etc.)

    Hope that helps,
    Matan