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

Discussion in 'Java' started by Steve Jasper, Oct 17, 2003.

  1. Steve Jasper

    Steve Jasper Guest

    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....
    Steve Jasper, Oct 17, 2003
    #1
    1. Advertising

  2. Steve Jasper

    Paul Lutus Guest

    Steve Jasper wrote:

    < snip >

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


    Like posting your code?

    --
    Paul Lutus
    http://www.arachnoid.com
    Paul Lutus, Oct 17, 2003
    #2
    1. Advertising

  3. Steve Jasper

    Phil... Guest

    on UNIX or Linux use "tee"

    "Paul Lutus" <> wrote in message
    news:...
    > Steve Jasper wrote:
    >
    > < snip >
    >
    > > Can anyone offer any suggestions? I feel like I'm missing something
    > > real easy....

    >
    > Like posting your code?
    >
    > --
    > Paul Lutus
    > http://www.arachnoid.com
    >
    Phil..., Oct 21, 2003
    #3
  4. Steve Jasper

    Paul Lutus Guest

    Phil... wrote:

    > 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.

    --
    Paul Lutus
    http://www.arachnoid.com
    Paul Lutus, Oct 21, 2003
    #4
  5. Steve Jasper wrote:

    > 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
    John C. Bollinger, Oct 21, 2003
    #5
  6. Steve Jasper

    soft-eng Guest

    (Steve Jasper) wrote in message news:<>...
    > 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.
    soft-eng, Oct 22, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. brrrdog
    Replies:
    0
    Views:
    815
    brrrdog
    Jul 9, 2003
  2. Replies:
    2
    Views:
    3,573
  3. mazdotnet
    Replies:
    1
    Views:
    508
    Mark Fitzpatrick
    Jan 29, 2008
  4. Bill Reid
    Replies:
    11
    Views:
    447
    Bill Reid
    May 31, 2008
  5. jose
    Replies:
    1
    Views:
    1,093
    Alexey Smirnov
    Jul 20, 2009
Loading...

Share This Page