com.sun.jini.phoenix
Class PipeWriter

java.lang.Object
  extended by com.sun.jini.phoenix.PipeWriter
All Implemented Interfaces:
Runnable

 class PipeWriter
extends Object
implements Runnable

PipeWriter plugs together two pairs of input and output streams by providing readers for input streams and writing through to appropriate output streams. Both output streams are annotated on a per-line basis.

Since:
2.0
Author:
Sun Microsystems, Inc.

Field Summary
private  ByteArrayOutputStream bufOut
          stream used for buffering lines
private  int cLast
          count since last separator
private  byte[] currSep
          current chunk of input being compared to lineSeparator.
private  Object[] date
           
private  String execString
           
private static String format
           
private static MessageFormat formatter
           
private  InputStream in
           
private static String lineSeparator
           
private static int lineSeparatorLength
           
private  PrintWriter out
           
 
Constructor Summary
private PipeWriter(InputStream in, OutputStream out, String name, String tag)
          Create a new PipeWriter object.
 
Method Summary
private  String createAnnotation()
          Create an annotation string to be printed out after a new line and end of stream.
(package private) static void plugTogetherPair(String name, InputStream in, OutputStream out, InputStream in1, OutputStream out1)
          Allow plugging together two pipes at a time, to associate output from an exec'ed process.
 void run()
          Create a thread to listen and read from input stream, in.
private  void write(byte b)
          Write a byte of data to the stream.
private  void write(byte[] b, int off, int len)
          Write a subarray of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bufOut

private final ByteArrayOutputStream bufOut
stream used for buffering lines


cLast

private int cLast
count since last separator


currSep

private final byte[] currSep
current chunk of input being compared to lineSeparator.


out

private final PrintWriter out

in

private final InputStream in

execString

private final String execString

date

private final Object[] date

lineSeparator

private static final String lineSeparator

lineSeparatorLength

private static final int lineSeparatorLength

format

private static final String format
See Also:
Constant Field Values

formatter

private static final MessageFormat formatter
Constructor Detail

PipeWriter

private PipeWriter(InputStream in,
                   OutputStream out,
                   String name,
                   String tag)
Create a new PipeWriter object. All methods of PipeWriter, except plugTogetherPair, are only accessible to PipeWriter itself. Synchronization is unnecessary on functions that will only be used internally in PipeWriter.

Parameters:
in - input stream from which pipe input flows
out - output stream to which log messages will be sent
name - name of the process
tag - name of the stream (out or err)
Method Detail

run

public void run()
Create a thread to listen and read from input stream, in. buffer the data that is read until a marker which equals lineSeparator is read. Once such a string has been discovered; write out an annotation string followed by the buffered data and a line separator.

Specified by:
run in interface Runnable

write

private void write(byte[] b,
                   int off,
                   int len)
            throws IOException
Write a subarray of bytes. Pass each through write byte method.

Throws:
IOException

write

private void write(byte b)
            throws IOException
Write a byte of data to the stream. If we have not matched a line separator string, then the byte is appended 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

createAnnotation

private String createAnnotation()
Create an annotation string to be printed out after a new line and end of stream.


plugTogetherPair

static void plugTogetherPair(String name,
                             InputStream in,
                             OutputStream out,
                             InputStream in1,
                             OutputStream out1)
Allow plugging together two pipes at a time, to associate output from an exec'ed process.

Parameters:
name - name of the process
in - input stream from which pipe input comes
out - output stream to which log messages will be sent
in1 - input stream from which pipe input comes
out1 - output stream to which log messages will be sent


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