public abstract class AbstractInputStreamConsumer extends java.lang.Object implements InputStreamConsumer
Provides a call()
, cancel()
, and
postProcessData()
implementation.
Modifier and Type | Field and Description |
---|---|
protected java.io.InputStream |
stream
The stream to read.
|
Constructor and Description |
---|
AbstractInputStreamConsumer(java.io.InputStream stream)
Creates an instance with the specified stream.
|
Modifier and Type | Method and Description |
---|---|
java.nio.ByteBuffer |
call()
Calls
read() until it returns -1, then calls
postProcessData() , and then calls data() , returning what
data() returns. |
void |
cancel()
Stops this consumer by closing the input stream.
|
protected abstract java.nio.ByteBuffer |
data()
Returns the data consumed from the input stream.
|
protected void |
postProcessData()
Performs post-processing of data.
|
protected abstract int |
read()
Reads a chunk of data from the input stream.
|
public AbstractInputStreamConsumer(java.io.InputStream stream)
stream
- stream from which to readjava.lang.IllegalArgumentException
- if stream
is null
public java.nio.ByteBuffer call() throws java.io.IOException
read()
until it returns -1, then calls
postProcessData()
, and then calls data()
, returning what
data()
returns.call
in interface java.util.concurrent.Callable<java.nio.ByteBuffer>
java.io.IOException
public void cancel()
cancel
in interface CancelableCallable<java.nio.ByteBuffer>
protected abstract java.nio.ByteBuffer data()
protected abstract int read() throws java.io.IOException
java.io.IOException
- if an I/O error occursprotected void postProcessData()
This method does nothing, but subclasses may override it to do something.