UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.io
Class Pipe

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--edu.berkeley.guir.lib.io.Pipe
All Implemented Interfaces:
Runnable

public class Pipe
extends Thread

Creates a one-way pipe between an arbitrary InputStream and an OutputStream, forwarding anything in the InputStream into the OutputStream. Anything available in this InputStream will be automatically fed into the OutputStream.

The Pipe will call the PipeCallback object (if provided) when either end of the Pipe is closed.

The Pipe will filter the bytes appropriately if provided a Filter object.

 You provide      Provided      You provide
 InputStream   ->   Pipe   ->   OutputStream
 

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Jun 16 1998, JH
               Created class
             - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Since:
JDK 1.1.6
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Pipe(InputStream istream, OutputStream ostream)
          Create a Pipe between the specified InputStream and OutputStream.
Pipe(InputStream istream, OutputStream ostream, PipeCallback cb)
          Create a Pipe between the specified InputStream and OutputStream.
 
Method Summary
 void close()
          Close the pipe.
 long getNumberOfBytesTransferred()
          Return the number of bytes transferred by the pipe.
static void main(String[] argv)
           
 void run()
           
 void setCallback(PipeCallback cb)
          Sets the pipe callback, which is called when the pipe closes.
 void setFilter(Filter f)
          Set the filter inside of this Pipe.
 void setInputStream(InputStream istream)
          Set where we get our input from.
 void setOutputStream(OutputStream ostream)
          Set where we send our output to.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pipe

public Pipe(InputStream istream,
            OutputStream ostream)
Create a Pipe between the specified InputStream and OutputStream.
Parameters:
istream - is the where we get input from.
ostream - is the where we send output to.

Pipe

public Pipe(InputStream istream,
            OutputStream ostream,
            PipeCallback cb)
Create a Pipe between the specified InputStream and OutputStream.
Parameters:
istream - is the where we get input from.
ostream - is the where we send output to.
cb - is the callback, called when the pipe closes.
Method Detail

run

public void run()
Overrides:
run in class Thread

setCallback

public void setCallback(PipeCallback cb)
Sets the pipe callback, which is called when the pipe closes.
Parameters:
cb - is the callback. Use null for no callback.

setOutputStream

public void setOutputStream(OutputStream ostream)
Set where we send our output to.
Parameters:
ostream - is the where we send output to.

setInputStream

public void setInputStream(InputStream istream)
Set where we get our input from.
Parameters:
istream - is the where we get input from.

close

public void close()
Close the pipe.

setFilter

public void setFilter(Filter f)
Set the filter inside of this Pipe.
Parameters:
f - is the filter. A null value means do not filter at all.

getNumberOfBytesTransferred

public long getNumberOfBytesTransferred()
Return the number of bytes transferred by the pipe.
Returns:
a long containing the number of bytes.

main

public static void main(String[] argv)
                 throws Exception

Copyright Information