Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

merging streams

Thread view: 
Guillaume ALLEON - 21 Mar 2006 07:56 GMT
What's the better way in Java to merge Stdout and Stderr and
generate a new stream that tou can query ?

cheers
guillaume
opalpa@gmail.com opalinski from opalpaweb - 21 Mar 2006 13:50 GMT
java.lang.System has setErr and setOut so you can merge.

> new stream that tou can query ?

after correcting typo of "tou" to "you" I still do not know what you
are talking about.

All the best,
Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
gal - 21 Mar 2006 16:20 GMT
Hi,

I want to generalize what is going on for ProcessBuilder in Java5 where
you can merge
stderr & stdout
Then when merged a query on stdout through a buffered reader gives you
either a line coming from stderr or from stdout.

My question is how to to this for let say a class having 2 streams.
What would be
the piece of code that would allow me to merge these 2 strams in one. A
kind of PipedReader allowing to connect to two writers

cheers
Guillaume
opalpa@gmail.com opalinski from opalpaweb - 21 Mar 2006 16:55 GMT
OK, one possibility, a starting point anyway:

Implement a subclass of OutputStream.  Have your subclass of
outputstream write contents to a buffer.  Add methods to your subclass
to retrieve contents of buffer.

Now you can pass an instance of your subclass when creating an instance
of java.io.PrintStream.  Pass the PrintStream instance to setErr and
setOut.

After that all things written on stdout and stderr will be going into
buffer of your subclass of OutputStream.

GIYF.  Maybe someone done parts of this already.

Good luck, have fun.

PS. I'm thinking specify automatic flush when constructing PrintStream
instance with your OutputStream instance.

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
Oliver Wong - 21 Mar 2006 17:48 GMT
<opalpa@gmail.com> wrote in message
news:1142956533.664562.248550@e56g2000cwe.googlegroups.com...
> OK, one possibility, a starting point anyway:
>
[quoted text clipped - 15 lines]
> PS. I'm thinking specify automatic flush when constructing PrintStream
> instance with your OutputStream instance.

   Note that your program will not be deterministic. That is, if a message
arrives on STDOUT and another one arrives on STDERR, it is not well defined
which message arrived "first" and which one arrived "second". Be sure to
take this into account when you perform your queries on this merged buffer.

   - Oliver
vjg - 21 Mar 2006 19:23 GMT
Safety tip: Do NOT cross the streams...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.