All Packages This Package Class Hierarchy Class Search Index
java.lang.Object | +----glguerin.util.Streamer
Summary |
public class Streamer extends java.lang.Object implements java.lang.Runnable { // Fields 6 protected byte[] buffer; protected boolean closeInput; protected boolean closeOutput; protected boolean flush; protected InputStream in; protected OutputStream out; // Constructors 1 public Streamer(byte[], InputStream, boolean, OutputStream, boolean, boolean); // Methods 3 public Thread makeDaemon(ThreadGroup, String); public long pump() throws IOException; public void run(); }
A Streamer "pumps" an InputStream to an OutputStream until EOF. If the OutputStream is null, then the InputStream is simply consumed until EOF. If the InputStream is null, then nothing is read and nothing is written to the OutputStream. A null InputStream is not generally useful, but it won't fail.
A Streamer implements Runnable with a run() method that simply calls pump(), ignores IOExceptions, and returns on completion. This is so a Thread can pump() a Streamer with no other intervening code. The makeDaemon() method makes a daemon Thread that does this.
Cross Reference |
Fields |
· buffer | Summary | Top |
protected byte[] buffer
The buffer assigned in constructor.
· in | Summary | Top |
protected InputStream in
The InputStream assigned in constructor, which may be null.
· closeInput | Summary | Top |
protected boolean closeInput
Whether to close InputStream or not.
· out | Summary | Top |
protected OutputStream out
The OutputStream assigned in constructor, which may be null.
· closeOutput | Summary | Top |
protected boolean closeOutput
Whether to close and/or flush OutputStream or not.
· flush | Summary | Top |
protected boolean flush
Whether to close and/or flush OutputStream or not.
Constructors |
· Streamer | Summary | Top |
public Streamer(byte[] buffer, InputStream in, boolean closeInput, OutputStream out, boolean closeOutput, boolean flushOutput)
Create with given buffer, streams, and stream-closing policies. The InputStream and/or OutputStream may be null. The buffer must be non-null.
If flushOutput is T, the OutputStream will be flush()'ed each time data is written to it. If F, then the OutputStream is not overtly flush()'ed while pumping data.
The OutputStream is always flush()'ed when the InputStream returns EOF, regardless of the state of flushOutput. This is done because the OutputStream may not be closed, and we want to push all the pumped data through.
Methods |
· pump | Summary | Top |
public long pump() throws IOException
"Pump" the InputStream to the OutputStream until EOF, returning the count of bytes transferred. The streams will be closed on successful return if so designated in the constructor. Neither stream will be closed if an IOException is thrown.
· run | Summary | Top |
public void run()
Call pump(), ignoring IOExceptions.
- Implements:
- run in interface Runnable
· makeDaemon | Summary | Top |
public Thread makeDaemon(ThreadGroup group, String threadName)
Make a daemon Thread with given name and ThreadGroup, that run()'s this Streamer when start()'ed. The returned Thread is not started.
If the ThreadGroup is null, the current Thread's ThreadGroup is used. If threadName is null, the new Thread's name is generated automatically. If both are null, then both defaults happen.
All Packages This Package Class Hierarchy Class Search IndexFreshly brewed Java API Documentation automatically generated with polardoc Version 1.0.7