org.scijava.util
Class ReadInto

java.lang.Object
  extended by java.lang.Thread
      extended by org.scijava.util.ReadInto
All Implemented Interfaces:
Runnable

public class ReadInto
extends Thread

This class takes an InputStream and either accumulates the read bytes in a String or outputs to a PrintStream.

Its intended use is to catch the output and error streams of Process instances.

Author:
Johannes Schindelin

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  StringBuilder buffer
           
protected  boolean closeOnEOF
           
protected  boolean done
           
protected  PrintStream out
           
protected  BufferedReader reader
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ReadInto(InputStream in, PrintStream out)
          Construct a ReadInto thread and start it right away.
ReadInto(InputStream in, PrintStream out, boolean closeOnEOF)
          Construct a ReadInto thread and start it right away.
 
Method Summary
 void done()
           
 void interrupt()
           
 void run()
          The main method.
 String toString()
          Return the output as a String unless a PrintStream was specified in the constructor.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

reader

protected BufferedReader reader

out

protected PrintStream out

buffer

protected StringBuilder buffer

done

protected boolean done

closeOnEOF

protected boolean closeOnEOF
Constructor Detail

ReadInto

public ReadInto(InputStream in,
                PrintStream out)
Construct a ReadInto thread and start it right away.

Parameters:
in - the stream to read
out - the stream to print to; if it is null, the toString() method will have the output instead

ReadInto

public ReadInto(InputStream in,
                PrintStream out,
                boolean closeOnEOF)
Construct a ReadInto thread and start it right away.

Parameters:
in - the stream to read
out - the stream to print to; if it is null, the toString() method will have the output instead
Method Detail

run

public void run()
The main method.

It runs until interrupted, or until the InputStream ends, whichever comes first.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

interrupt

public void interrupt()
Overrides:
interrupt in class Thread

done

public void done()
          throws IOException
Throws:
IOException

toString

public String toString()
Return the output as a String unless a PrintStream was specified in the constructor.

Overrides:
toString in class Thread


Copyright © 2009–2015 SciJava. All rights reserved.