I have an method which writes data to an OutputStream but needs to return the contents of the OutputStream as an InputStream
public InputStream getInputStreamOfData(type param) {
// ..... data
OutputStreamWriter writer = new OutputStreamWriter();
writer.write(data);
// convert writer object to an InputStream
}
I came across some libraries to do this such as IOUtils and other thread based methods. Is there a simple way to achieve this using standard Java library ? I want to return the contents in the writer as an InputStream to be consumed by the calling method.
Thanks!
Write to a
ByteArrayOutputStream, then get the byte array, and return aByteArrayInputStreamfrom this byte array.