public abstract class AbstractBufferedDataFetcher extends AbstractDataFetcher
AbstractBufferedDataFetcher is a sensible base implementation of
DataFetcher that uses a byte[] as buffer, to while copying
all bytes from an InputStream to an OutputStream by
sequentially reading from the InputStream into the buffer and then
writing from the buffer to the OutputStream.
Implementers must only implement the methods
obtainBuffer() and
returnBuffer(byte[]) that manage a
byte[] to be used as a buffer in
doCopy(InputStream, OutputStream, DataFetchProgressListener).
Implementers may also override
returnBuffer(byte[]), which is called
after
doCopy(InputStream, OutputStream, DataFetchProgressListener)
has finished using it.
| Modifier and Type | Field and Description |
|---|---|
protected static int |
DEFAULT_BUFEFR_SIZE
The default buffer size of 1024 bytes.
|
| Constructor and Description |
|---|
AbstractBufferedDataFetcher() |
| Modifier and Type | Method and Description |
|---|---|
protected static byte[] |
createBuffer(int bufferSize)
Safely creates a new byte[] to be used as a buffer.
|
protected void |
doCopy(InputStream in,
OutputStream out,
DataFetchProgressListener listener)
Copies the content of a given
InputStream into a given
OutputStream. |
protected abstract byte[] |
obtainBuffer()
Called by
doCopy(InputStream, OutputStream, DataFetchProgressListener)
to obtain a byte[] to be used as a buffer. |
protected abstract void |
returnBuffer(byte[] buffer)
Called by
doCopy(InputStream, OutputStream, DataFetchProgressListener)
to return a byte[] that has previously been obtained from
obtainBuffer(). |
protected static final int DEFAULT_BUFEFR_SIZE
protected static final byte[] createBuffer(int bufferSize)
bufferSize - The size of the byte[] to be created. Defaults to
the default buffer size, if the given buffer size is not
positive.protected final void doCopy(InputStream in, OutputStream out, DataFetchProgressListener listener) throws DataFetchException
AbstractDataFetcherInputStream into a given
OutputStream.
It is guaranteed that neither the given InputStream nor the given
OutputStream nor the given DataFetchProgressListener is
null.
Implementers must not close either of the given streams.
doCopy in class AbstractDataFetcherin - The InputStream to read from.out - The OutputStream to write to.listener - The DataFetchProgressListener to report to.DataFetchException - If anything went wrong while reading from the given
InputStream or writing to the given
OutputStream.protected abstract byte[] obtainBuffer()
doCopy(InputStream, OutputStream, DataFetchProgressListener)
to obtain a byte[] to be used as a buffer.
Every byte[] that is returned by this method will be passed as an
argument of returnBuffer(byte[])
after
doCopy(InputStream, OutputStream, DataFetchProgressListener)
has finished using it.
byte[] to be used as a buffer.protected abstract void returnBuffer(byte[] buffer)
doCopy(InputStream, OutputStream, DataFetchProgressListener)
to return a byte[] that has previously been obtained from
obtainBuffer().buffer - The byte[] to be returned.Copyright © 2015–2016 Markenwerk – Gesellschaft für markenbildende Maßnahmen mbH. All rights reserved.