Writing OutputStream to String[] array? I'm stumped.....

S

Steve Jasper

I'm trying to redirect the Standard System.out to a custom
OutputStream in order to collect and add each write() to a String,
which I will later save off for a variety of other purposes.

I can redirect the standard system.out using System.setOut() without
any problem, but I'm not sure how to intercept every write().

Essentially my goal is to have everything being printed to the console
to also be collected into String objects and stored in a HashMap or
Vector for later use.

Can anyone offer any suggestions? I feel like I'm missing something
real easy....
 
P

Paul Lutus

Phil... said:
on UNIX or Linux use "tee"

No, the OP needs to post his code. Using the methods of the Process class,
he can get what he wants, exactly. No system-specific calls needed.
 
J

John C. Bollinger

Steve said:
I'm trying to redirect the Standard System.out to a custom
OutputStream in order to collect and add each write() to a String,
which I will later save off for a variety of other purposes.

I can redirect the standard system.out using System.setOut() without
any problem, but I'm not sure how to intercept every write().

You override some or all of OutputStream's write() methods in your
custom OutputStream, and insert there the behavior you want. If you
have need then from the code of your custom class you may invoke the
parent class' write(...) methods as super.write(...).

If you need further assistance then it will be to your advantage to post
what you've done so far.


John Bollinger
(e-mail address removed)
 
S

soft-eng

I'm trying to redirect the Standard System.out to a custom
OutputStream in order to collect and add each write() to a String,
which I will later save off for a variety of other purposes.

I can redirect the standard system.out using System.setOut() without
any problem, but I'm not sure how to intercept every write().

Essentially my goal is to have everything being printed to the console
to also be collected into String objects and stored in a HashMap or
Vector for later use.

Can anyone offer any suggestions? I feel like I'm missing something
real easy....

As it happens, this particular problem is used as an
example program in this tutorial:

http://developer.java.sun.com/developer/technicalArticles/Streams/WritingIOSC/

Look at the "TeeOutputStream" example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top