Thursday, April 22, 2010

Converting an OutputStream to an InputStream

This old problem again... I need an input stream in my test - but how do I create it? This guy knows. Thanks!

final PipedOutputStream pout = new PipedOutputStream();
new Thread(new Runnable(){
public void run(){
DataOutput output = new DataOutputStream(pout);
// write to output stream here
}
}
).start();
DataInputStream in = new DataInputStream(new PipedInputStream(pout));