bytearrayoutputstream

Most efficient way to create InputStream from OutputStream

▼魔方 西西 提交于 2019-11-26 21:28:11
This page: http://blog.ostermiller.org/convert-java-outputstream-inputstream describes how to create an InputStream from OutputStream: new ByteArrayInputStream(out.toByteArray()) Other alternatives are to use PipedStreams and new threads which is cumbersome. I do not like the idea of copying many megabytes to new in memory byte array. Is there a library that does this more efficiently? EDIT: By advice from Laurence Gonsalves, i tried PipedStreams and it turned out they are not that hard to deal with. Here's the sample code in clojure: (defn #^PipedInputStream create-pdf-stream [pdf-info] (let