Methods Summary |
---|
public synchronized int | getBufferSize()Get the size in bytes of the read buffer.
return bufferSize;
|
public synchronized java.lang.Exception | getException()Get the exception encountered, if any.
return exception;
|
public boolean | isFinished()Tells whether the end of the stream has been reached.
return finished;
|
public void | run()Copies data from the input stream to the output stream.
Terminates as soon as the input stream is closed or an error occurs.
synchronized (this) {
started = true;
}
finished = false;
finish = false;
final byte[] buf = new byte[bufferSize];
int length;
try {
while ((length = is.read(buf)) > 0 && !finish) {
os.write(buf, 0, length);
if (autoflush) {
os.flush();
}
}
os.flush();
} catch (Exception e) {
synchronized (this) {
exception = e;
}
} finally {
if (closeWhenExhausted) {
try {
os.close();
} catch (IOException e) {
// ignore
}
}
finished = true;
synchronized (this) {
notifyAll();
}
}
|
void | setAutoflush(boolean autoflush)Set whether data should be flushed through to the output stream.
this.autoflush = autoflush;
|
public synchronized void | setBufferSize(int bufferSize)Set the size in bytes of the read buffer.
if (started) {
throw new IllegalStateException(
"Cannot set buffer size on a running StreamPumper");
}
this.bufferSize = bufferSize;
|
synchronized void | stop()Stop the pumper as soon as possible.
Note that it may continue to block on the input stream
but it will really stop the thread as soon as it gets EOF
or any byte, and it will be marked as finished.
finish = true;
notifyAll();
|
public synchronized void | waitFor()This method blocks until the stream pumper finishes.
while (!isFinished()) {
wait();
}
|