public final class BufferedDataFetcher extends AbstractBufferedDataFetcher
AbstractBufferedDataFetcher is a sensible base implementation of
DataFetcher that uses a byte[] as buffer, 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.
The buffer is eagerly allocated in the constructor just once and then used
for every operation. A BufferedDataFetcher is therefore not
threadsafe.
After a buffer has been used, it is overwritten with zeros, to remove any buffered information from the memory.
DEFAULT_BUFEFR_SIZE| Constructor and Description |
|---|
BufferedDataFetcher()
Creates a new
BufferedDataFetcher with the default buffer size of
1024 bytes. |
BufferedDataFetcher(int bufferSize)
Creates a new
BufferedDataFetcher with the given buffer size. |
| Modifier and Type | Method and Description |
|---|---|
protected byte[] |
obtainBuffer()
Called by
AbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)
to obtain a byte[] to be used as a buffer. |
protected void |
returnBuffer(byte[] buffer)
Called by
AbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)
to return a byte[] that has previously been obtained from
AbstractBufferedDataFetcher.obtainBuffer(). |
createBuffer, doCopypublic BufferedDataFetcher()
BufferedDataFetcher with the default buffer size of
1024 bytes.public BufferedDataFetcher(int bufferSize)
BufferedDataFetcher with the given buffer size.bufferSize - The buffer size.protected byte[] obtainBuffer()
AbstractBufferedDataFetcherAbstractBufferedDataFetcher.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 AbstractBufferedDataFetcher.returnBuffer(byte[])
after
AbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)
has finished using it.
obtainBuffer in class AbstractBufferedDataFetcherbyte[] to be used as a buffer.protected void returnBuffer(byte[] buffer)
AbstractBufferedDataFetcherAbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)
to return a byte[] that has previously been obtained from
AbstractBufferedDataFetcher.obtainBuffer().returnBuffer in class AbstractBufferedDataFetcherbuffer - The byte[] to be returned.Copyright © 2015–2016 Markenwerk – Gesellschaft für markenbildende Maßnahmen mbH. All rights reserved.