com.sun.jini.tool.envcheck
Class EnvCheck.Pipe

java.lang.Object
  extended by com.sun.jini.tool.envcheck.EnvCheck.Pipe
All Implemented Interfaces:
Runnable
Enclosing class:
EnvCheck

private class EnvCheck.Pipe
extends Object
implements Runnable

An I/O redirection pipe. A daemon thread copies data from an input stream to an output stream. An optional annotation may be provided which will prefix each line of the copied data with a label which can be used to identify the source.


Field Summary
private  String annotation
          the output stream annotation
private  ByteArrayOutputStream bufOut
          output line buffer
private  InputStream in
          the input stream
private  Thread outThread
          the thread to process the data
private static byte SEPARATOR
          the line separator character
private  PrintStream stream
          the output PrintStream
 
Constructor Summary
EnvCheck.Pipe(String name, InputStream in, PrintStream stream, String a)
          Create a new Pipe object and start the thread to handle the data.
 
Method Summary
 void run()
          Read and write data until EOF is detected.
(package private)  void waitTillEmpty(int timeout)
          Wait until the run method terminates due to reading EOF on input
private  void write(byte b)
          If not annotated, write the byte to the stream immediately.
private  void write(byte[] b, int len)
          Write each byte in the give byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

private static final byte SEPARATOR
the line separator character

See Also:
Constant Field Values

bufOut

private ByteArrayOutputStream bufOut
output line buffer


in

private InputStream in
the input stream


stream

private PrintStream stream
the output PrintStream


annotation

private String annotation
the output stream annotation


outThread

private Thread outThread
the thread to process the data

Constructor Detail

EnvCheck.Pipe

EnvCheck.Pipe(String name,
              InputStream in,
              PrintStream stream,
              String a)
Create a new Pipe object and start the thread to handle the data.

Parameters:
name - the name to assign to the thread
in - input stream from which pipe input flows
stream - the stream to which output will be sent
a - the annotation for prepending text to logged lines
Method Detail

waitTillEmpty

void waitTillEmpty(int timeout)
Wait until the run method terminates due to reading EOF on input

Parameters:
timeout - max time to wait for the thread to terminate

run

public void run()
Read and write data until EOF is detected. Flush any remaining data to the output steam and return, terminating the thread.

Specified by:
run in interface Runnable

write

private void write(byte[] b,
                   int len)
            throws IOException
Write each byte in the give byte array.

Parameters:
b - the array of input bytes
len - the number data bytes in the array
Throws:
IOException

write

private void write(byte b)
            throws IOException
If not annotated, write the byte to the stream immediately. Otherwise, write a byte of data to the internal buffer. If we have matched a line separator, then the currently buffered line is sent to the output writer with a prepended annotation string.

Throws:
IOException


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.