ch.javasoft.job
Class PipeJob

java.lang.Object
  extended by ch.javasoft.job.AbstractJob<Void>
      extended by ch.javasoft.job.PipeJob
All Implemented Interfaces:
Executable<Void>, Job<Void>

public class PipeJob
extends AbstractJob<Void>

A PipeJob pipes an input stream to an output stream, i.e. it writes to the output stream what it reads from the input stream, typically in its own thread.


Constructor Summary
PipeJob(InputStream src, OutputStream dst)
          Constructs a new PipeJob with the given streams to pipe, using a buffer of default size (1024 bytes).
PipeJob(InputStream src, OutputStream dst, byte[] buffer)
          Constructs a new PipeJob with the given streams to pipe, using the given buffer.
 
Method Summary
static JobMonitor<Void> pipe(InputStream src, OutputStream dst)
          Pipe the specified input stream to the output stream.
static JobMonitor<Void> pipe(InputStream src, OutputStream dst, byte[] buffer)
          Pipe the specified input stream to the output stream.
 Void run()
          Executes the job, blocks until the result is present or an exception is thrown.
 
Methods inherited from class ch.javasoft.job.AbstractJob
exec, exec, execAndWait, execAndWaitThrowException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PipeJob

public PipeJob(InputStream src,
               OutputStream dst)
Constructs a new PipeJob with the given streams to pipe, using a buffer of default size (1024 bytes).

Parameters:
src - the input stream to read from
dst - the output stream to write to

PipeJob

public PipeJob(InputStream src,
               OutputStream dst,
               byte[] buffer)
Constructs a new PipeJob with the given streams to pipe, using the given buffer.

Parameters:
src - the input stream to read from
dst - the output stream to write to
buffer - the buffer to use when piping input to output
Method Detail

run

public Void run()
         throws IOException
Description copied from interface: Job
Executes the job, blocks until the result is present or an exception is thrown.
Note: It is usually not a good idea to call this method manually, but to let this job be executed by a JobProcessor. Most job implementations also implement Executable with the more preferable Executable.exec() and Executable.execAndWait() methods.

Returns:
the job result, or null of type Void for void methods
Throws:
IOException

pipe

public static JobMonitor<Void> pipe(InputStream src,
                                    OutputStream dst)
Pipe the specified input stream to the output stream. The data transfer is performed in a new thread.

Parameters:
src - the input stream from which data is read
dst - the output stream to write the data to
Returns:
a monitor for the pipe process

pipe

public static JobMonitor<Void> pipe(InputStream src,
                                    OutputStream dst,
                                    byte[] buffer)
Pipe the specified input stream to the output stream. The data transfer is performed in a new thread.

Parameters:
src - the input stream from which data is read
dst - the output stream to write the data to
buffer - the buffer to use when copying from in to out
Returns:
a monitor for the pipe process