Class BufferedDataFetcher
- java.lang.Object
-
- net.markenwerk.utils.data.fetcher.AbstractDataFetcher
-
- net.markenwerk.utils.data.fetcher.AbstractBufferedDataFetcher
-
- net.markenwerk.utils.data.fetcher.BufferedDataFetcher
-
- All Implemented Interfaces:
DataFetcher
public final class BufferedDataFetcher extends AbstractBufferedDataFetcher
AbstractBufferedDataFetcheris a sensible base implementation ofDataFetcherthat uses abyte[]as buffer, while copying all bytes from anInputStreamto anOutputStreamby sequentially reading from theInputStreaminto the buffer and then writing from the buffer to theOutputStream.The buffer is eagerly allocated in the constructor just once and then used for every operation. A
BufferedDataFetcheris therefore not threadsafe.After a buffer has been used, it is overwritten with zeros, to remove any buffered information from the memory.
- Since:
- 4.0.0
- Author:
- Torsten Krause (tk at markenwerk dot net)
-
-
Field Summary
-
Fields inherited from class net.markenwerk.utils.data.fetcher.AbstractBufferedDataFetcher
DEFAULT_BUFEFR_SIZE
-
-
Constructor Summary
Constructors Constructor Description BufferedDataFetcher()Creates a newBufferedDataFetcherwith the default buffer size of 1024 bytes.BufferedDataFetcher(int bufferSize)Creates a newBufferedDataFetcherwith the given buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]obtainBuffer()Called byAbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)to obtain abyte[]to be used as a buffer.protected voidreturnBuffer(byte[] buffer)Called byAbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)to return abyte[]that has previously been obtained fromAbstractBufferedDataFetcher.obtainBuffer().-
Methods inherited from class net.markenwerk.utils.data.fetcher.AbstractBufferedDataFetcher
createBuffer, doCopy
-
-
-
-
Constructor Detail
-
BufferedDataFetcher
public BufferedDataFetcher()
Creates a newBufferedDataFetcherwith the default buffer size of 1024 bytes.
-
BufferedDataFetcher
public BufferedDataFetcher(int bufferSize)
Creates a newBufferedDataFetcherwith the given buffer size.- Parameters:
bufferSize- The buffer size.
-
-
Method Detail
-
obtainBuffer
protected byte[] obtainBuffer()
Description copied from class:AbstractBufferedDataFetcherCalled byAbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)to obtain abyte[]to be used as a buffer.Every
byte[]that is returned by this method will be passed as an argument ofAbstractBufferedDataFetcher.returnBuffer(byte[])afterAbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)has finished using it.- Specified by:
obtainBufferin classAbstractBufferedDataFetcher- Returns:
- The a
byte[]to be used as a buffer.
-
returnBuffer
protected void returnBuffer(byte[] buffer)
Description copied from class:AbstractBufferedDataFetcherCalled byAbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)to return abyte[]that has previously been obtained fromAbstractBufferedDataFetcher.obtainBuffer().- Specified by:
returnBufferin classAbstractBufferedDataFetcher- Parameters:
buffer- Thebyte[]to be returned.
-
-