Class StreamPrinter

java.lang.Object
gnu.dtools.ritopt.StreamPrinter
All Implemented Interfaces:
Stoppable, Runnable

public class StreamPrinter extends Object implements Runnable, Stoppable
Reads data from an input stream and outputs to a print stream. This class is used by the OptionMenu class to read from both standard output and standard error simultaneously when a shell command is executed. Since the StreamPrinter processes streams on a separate thread, deadlock is prevented.


 Copyright (C) Damian Ryan Eads, 2001. All Rights Reserved.

 ritopt is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 ritopt is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with ritopt; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new StreamPrinter.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether this StreamPrinter has stopped processing.
    void
    Joins this StreamPrinter's thread with the other threads.
    void
    run()
    Start the StreamPrinter thread.
    void
    setFlush(boolean flush)
    Sets whether the output stream should be flushed after each output step.
    void
    Sets the object to stop when this object is finished.
    void
    Starts the thread associated with this StreamPrinter.
    void
    Stops this StreamPrinter's processing.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StreamPrinter

      public StreamPrinter(InputStream s, PrintStream p)
      Constructs a new StreamPrinter.
      Parameters:
      s - The stream to read from.
      p - The stream to output to.
  • Method Details

    • start

      public void start() throws InterruptedException
      Starts the thread associated with this StreamPrinter.
      Throws:
      InterruptedException
    • setStop

      public void setStop(Stoppable tostop)
      Sets the object to stop when this object is finished.
      Parameters:
      tostop - The object to stop.
    • isStopped

      public boolean isStopped()
      Returns whether this StreamPrinter has stopped processing.
      Specified by:
      isStopped in interface Stoppable
      Returns:
      A boolean value.
    • setFlush

      public void setFlush(boolean flush)
      Sets whether the output stream should be flushed after each output step.
      Parameters:
      flush - A boolean value.
    • stop

      public void stop()
      Stops this StreamPrinter's processing.
      Specified by:
      stop in interface Stoppable
    • join

      public void join() throws InterruptedException
      Joins this StreamPrinter's thread with the other threads.
      Throws:
      InterruptedException
    • run

      public void run()
      Start the StreamPrinter thread. This is done automatically during construction.
      Specified by:
      run in interface Runnable