Set of useful, production ready, Java input and output streams.
JDK version 1.6 or above
Add the following dependency to Maven based builds:
<dependency>
<groupId>org.iostreams</groupId>
<artifactId>iostreams</artifactId>
<version>1.0</version>
</dependency>
One of the most useful classes in iostreams library is the OutputToInputStream
stream.
This class allows you easily convert an OutputSteam
to sources that expect an InputStream
.
OutputToInputStream
abstracts the complexities of piped streams and takes care of running the output in a separate thread. It's in use in enterprise production systems for several years.
A commons example is XML and JSON serializers that write to an OutputStream
and you need to pass it to method that works with InputStream
.
Here is a sample usage of the OutputToInputStream
class:
InputStream in = new OutputToInputStream() {
protected void write(OutputStream sink) throws IOException {
JacksonFactory.createJsonGenerator(sink).writeObject(toSerialize);
}
};
// class that expects an input stream
FileUtils.write(targetPath, in);
iostreams is licensed under the Apache 2 License.