A small confusion with Streams... Please help

I am working with j2ssh. I have OutputStream at hand and if i direct to System.out, or direct to file, it works fine.But I need to read the output line by line and check a string find in the that line, if not available print it. I think i need to connect outputstream to input stream. But i dont know how to do it. Please help me if any possibility.

OutputStream out=session.getOutputStream();

InputStream in = session.getInputStream();

OutputStream fos=new FileOutputStream ("c:\\aaa.txt");

DataOutputStream dos =new DataOutputStream (fos);

IOStreamConnector input=new IOStreamConnector(System.in,out);

IOStreamConnector output=new IOStreamConnector(in,fos);

Here session is ssh session.

Thanks,

Uma

[929 byte] By [umamittapallia] at [2007-10-2 22:02:34]
# 1

I guess you want to analyze the input stream ?!?

The input stream is whatever comes into your program from a source - for example an HTTP Stream, or a file.

On the other hand, the output stream totally depends on the data you put into it.

For reading String lines from the input stream, use a reader such as the BufferedReader:

http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html

Now you can manipulate your data, rebuild it and move it into the output stream via a BufferedWriter

http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedWriter.html

Mongera at 2007-7-14 1:19:03 > top of Java-index,Java Essentials,Java Programming...
# 2

An output stream connected directly to an inputstream is called a "pipe".

PipedInputStream and PipedOutputStream are the java implementations.

ps. The two halves of a pipe should almost always be in separate threads. You may need to add threading.

Message was edited by:

malcolmmc

malcolmmca at 2007-7-14 1:19:03 > top of Java-index,Java Essentials,Java Programming...
# 3

Thanks for your suggestion. J2ssh provies one class namely IOStreamConnector which will do the same action.

IOStreamConnector output=new IOStreamConnector(session.getInputStream,System.out);

Session -> -> stdout

which connects session inputstream to stdout. But I need the below behavoiur...Please give me a hint.

Session -> -> buffer( where i should get the output line by line) -> -> stdout/fileoutput

umamittapallia at 2007-7-14 1:19:03 > top of Java-index,Java Essentials,Java Programming...