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
AbstractBufferedDataFetcher
is a sensible base implementation ofDataFetcher
that uses abyte[]
as buffer, while copying all bytes from anInputStream
to anOutputStream
by sequentially reading from theInputStream
into 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
BufferedDataFetcher
is 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 newBufferedDataFetcher
with the default buffer size of 1024 bytes.BufferedDataFetcher(int bufferSize)
Creates a newBufferedDataFetcher
with 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 void
returnBuffer(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 newBufferedDataFetcher
with the default buffer size of 1024 bytes.
-
BufferedDataFetcher
public BufferedDataFetcher(int bufferSize)
Creates a newBufferedDataFetcher
with the given buffer size.- Parameters:
bufferSize
- The buffer size.
-
-
Method Detail
-
obtainBuffer
protected byte[] obtainBuffer()
Description copied from class:AbstractBufferedDataFetcher
Called 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:
obtainBuffer
in classAbstractBufferedDataFetcher
- Returns:
- The a
byte[]
to be used as a buffer.
-
returnBuffer
protected void returnBuffer(byte[] buffer)
Description copied from class:AbstractBufferedDataFetcher
Called byAbstractBufferedDataFetcher.doCopy(InputStream, OutputStream, DataFetchProgressListener)
to return abyte[]
that has previously been obtained fromAbstractBufferedDataFetcher.obtainBuffer()
.- Specified by:
returnBuffer
in classAbstractBufferedDataFetcher
- Parameters:
buffer
- Thebyte[]
to be returned.
-
-