Reputation: 91
I have a class CBZip2OutputStream from "apache bzi2 library" , it can transform binary data stream to bzi2 data stream. But I need to archive a string. Therefore, i think, i should create an input stream from that outputstream, write that data to outputstream and read archived data from inputstream... but how to link outputstream and inputstream?
Upvotes: 2
Views: 1076
Reputation: 777
You can use several method to get an InputStream out of an OutputStream.
Here is a complete tutorial.
Upvotes: 0
Reputation: 115328
You can just read from input stream and write to output stream. It is a common practice. IOUtils.copy() (from jakarta commons) does it, so you event do not need to implement the loop.
Alternatively you can use PipedInputStream and PipedOutputStream.
Upvotes: 2
Reputation:
First, you probably want a DataOutputStream: it is designed to take primitives and objects and convert them to bytes. It does handle strings as well.
Next, use piped I/O: PipedInputStream and PipedOutputStream. You can use them to link streams together, similar to piping input from one process into another from the command line.
Upvotes: 1