Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11677

Re: how to read back the lines printed out to the console?

From frame <xsli2@yahoo.com>
Newsgroups comp.lang.java.programmer
Subject Re: how to read back the lines printed out to the console?
Date 2012-01-31 10:09 -0800
Organization http://groups.google.com
Message-ID <3409fa75-d290-4501-80b5-fdb3f798df9a@s9g2000vbc.googlegroups.com> (permalink)
References <99599fa8-013c-4132-ac9e-5987d9d5588e@o13g2000vbf.googlegroups.com> <4f2736dd$0$291$14726298@news.sunsite.dk>

Show all headers | View raw


Wow. Thank you so much. I greatly appreciate your effort for putting
up such complete and nicely formatted code, including testing code.
Thank you very very much.

Like Patricia said, I am almost there. Based on your code, my class
ends up to be:

class TeeOutputStream extends OutputStream
{
    private final OutputStream os1;
//    private final OutputStream os2;
    private final Logger _logger;  //the class of Logger is our own
class

    public TeeOutputStream(final OutputStream os1, final Logger log)
    {
        this.os1 = os1;
//        this.os2 = os2;
        this._logger = log;
    }

    @Override
    public void write(final byte[] b) throws IOException
    {
        os1.write(b);
//        os2.write(b);
        this._logger.log(Logger.INFO, new String(b));
    }

    @Override
    public void write(final byte[] b, final int off, final int len)
throws IOException
    {
        os1.write(b, off, len);
//        os2.write(b, off, len);
        this._logger.log(Logger.INFO, new String(b, off, len));
    }

    @Override
    public void write(final int b) throws IOException
    {
        os1.write(b);
//        os2.write(b);
        this._logger.log(Logger.INFO, String.valueOf((char)b));
    }

    @Override
    public void flush() throws IOException
    {
        os1.flush();
//        os2.flush();
    }

    @Override
    public void close() throws IOException
    {
        os1.close();
        this._logger.close();
    }
}

At the place of calling this class,

            final TeeOutputStream teeOutputStream = new
TeeOutputStream(System.out, logger);

            System.setOut(new PrintStream(teeOutputStream));

Since now, all System.out.println(..) message is shown on the console
progressively when the program running and be saved into a file at the
end by writing out our logger object to a xml file.

Thank you again for all the help.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-01-30 12:03 -0800
  Re: how to read back the lines printed out to the console? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-01-30 20:18 +0000
    Re: how to read back the lines printed out to the console? Roedy Green <see_website@mindprod.com.invalid> - 2012-01-30 20:42 -0800
  Re: how to read back the lines printed out to the console? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-30 14:18 -0800
    Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 19:34 -0500
  Re: how to read back the lines printed out to the console? Patricia Shanahan <pats@acm.org> - 2012-01-30 14:37 -0800
    Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 20:08 -0500
      Re: how to read back the lines printed out to the console? Patricia Shanahan <pats@acm.org> - 2012-01-30 17:18 -0800
        Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 21:00 -0500
  Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 19:33 -0500
    Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 19:35 -0500
    Re: how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-01-31 10:09 -0800
      Re: how to read back the lines printed out to the console? Lew <noone@lewscanon.com> - 2012-01-31 11:11 -0800
        Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-31 20:39 -0500
        Re: how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-02-01 06:01 -0800
          Re: how to read back the lines printed out to the console? Ian Shef <invalid@avoiding.spam> - 2012-02-01 19:15 +0000
            Re: how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-02-01 12:59 -0800
              Re: how to read back the lines printed out to the console? Gene Wirchenko <genew@ocis.net> - 2012-02-01 14:00 -0800
          Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-01 19:27 -0500
  Re: how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-01-30 18:49 -0800
    Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 21:56 -0500
    Re: how to read back the lines printed out to the console? Patricia Shanahan <pats@acm.org> - 2012-01-30 19:06 -0800
    Re: how to read back the lines printed out to the console? Roedy Green <see_website@mindprod.com.invalid> - 2012-01-30 20:46 -0800
    Re: how to read back the lines printed out to the console? Lew <noone@lewscanon.com> - 2012-01-30 21:18 -0800
      Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-31 20:36 -0500
    Re: how to read back the lines printed out to the console? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2012-01-31 10:18 +0200
      Re: how to read back the lines printed out to the console? Lew <noone@lewscanon.com> - 2012-01-31 11:15 -0800
    Re: how to read back the lines printed out to the console? bugbear <bugbear@trim_papermule.co.uk_trim> - 2012-01-31 09:50 +0000
      Re: how to read back the lines printed out to the console? Lew <noone@lewscanon.com> - 2012-01-31 11:17 -0800

csiph-web