Class AbstractDataFetcher
- java.lang.Object
-
- net.markenwerk.utils.data.fetcher.AbstractDataFetcher
-
- All Implemented Interfaces:
DataFetcher
- Direct Known Subclasses:
AbstractBufferedDataFetcher
public abstract class AbstractDataFetcher extends Object implements DataFetcher
AbstractDataFetcheris a sensible base implementation ofDataFetcher.Implementers must only implement a single simplified method that copies all bytes from an
InputStreamto anOutputStream:doCopy(InputStream, OutputStream, DataFetchProgressListener).- Since:
- 4.0.0
- Author:
- Torsten Krause (tk at markenwerk dot net)
-
-
Constructor Summary
Constructors Constructor Description AbstractDataFetcher()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcopy(InputStream in, OutputStream out)Copies the content of a givenInputStreaminto a givenOutputStream.voidcopy(InputStream in, OutputStream out, boolean closeIn, boolean closeOut)Copies the content of a givenInputStreaminto a givenOutputStream.voidcopy(InputStream in, OutputStream out, DataFetchProgressListener listener)Copies the content of a givenInputStreaminto a givenOutputStream.voidcopy(InputStream in, OutputStream out, DataFetchProgressListener listener, boolean closeIn, boolean closeOut)Copies the content of a givenInputStreaminto a givenOutputStream.protected abstract voiddoCopy(InputStream in, OutputStream out, DataFetchProgressListener listener)Copies the content of a givenInputStreaminto a givenOutputStream.byte[]fetch(InputStream in)Fetches the content of a givenInputStreaminto a fresh byte[].byte[]fetch(InputStream in, boolean close)Fetches the content of a givenInputStreaminto a fresh byte[].byte[]fetch(InputStream in, DataFetchProgressListener listener)Fetches the content of a givenInputStreaminto a fresh byte[].byte[]fetch(InputStream in, DataFetchProgressListener listener, boolean close)Fetches the content of a givenInputStreaminto a fresh byte[].
-
-
-
Method Detail
-
fetch
public final byte[] fetch(InputStream in) throws DataFetchException
Description copied from interface:DataFetcherFetches the content of a givenInputStreaminto a fresh byte[].See
DataFetcher.copy(InputStream, OutputStream, boolean, boolean)for the handling of missing or invalid arguments.- Specified by:
fetchin interfaceDataFetcher- Parameters:
in- TheInputStreamto read from.- Returns:
- A new
byte[], containing the content of the givenInputStream. - Throws:
DataFetchException- If anything went wrong while reading from the givenInputStream.
-
fetch
public final byte[] fetch(InputStream in, boolean close) throws DataFetchException
Description copied from interface:DataFetcherFetches the content of a givenInputStreaminto a fresh byte[].See
DataFetcher.copy(InputStream, OutputStream, boolean, boolean)for the handling of missing or invalid arguments.- Specified by:
fetchin interfaceDataFetcher- Parameters:
in- TheInputStreamto read from.close- Whether to close the givenInputStream, after reading from it.- Returns:
- A new
byte[], containing the content of the givenInputStream. - Throws:
DataFetchException- If anything went wrong while reading from the givenInputStream.FetchExceptionsthrown while trying to close the givenInputStream, if requested, are ignored.
-
fetch
public final byte[] fetch(InputStream in, DataFetchProgressListener listener) throws DataFetchException
Description copied from interface:DataFetcherFetches the content of a givenInputStreaminto a fresh byte[].See
DataFetcher.copy(InputStream, OutputStream, boolean, boolean)for the handling of missing or invalid arguments.- Specified by:
fetchin interfaceDataFetcher- Parameters:
in- TheInputStreamto read from.listener- TheDataFetchProgressListenerto report to.- Returns:
- A new
byte[], containing the content of the givenInputStream. - Throws:
DataFetchException- If anything went wrong while reading from the givenInputStream.
-
fetch
public final byte[] fetch(InputStream in, DataFetchProgressListener listener, boolean close) throws DataFetchException
Description copied from interface:DataFetcherFetches the content of a givenInputStreaminto a fresh byte[].See
DataFetcher.copy(InputStream, OutputStream, boolean, boolean)for the handling of missing or invalid arguments.- Specified by:
fetchin interfaceDataFetcher- Parameters:
in- TheInputStreamto read from.listener- TheDataFetchProgressListenerto report to.close- Whether to close the givenInputStream, after reading from it.- Returns:
- A new
byte[], containing the content of the givenInputStream. - Throws:
DataFetchException- If anything went wrong while reading from the givenInputStream.FetchExceptionsthrown while trying to close the givenInputStream, if requested, are ignored.
-
copy
public final void copy(InputStream in, OutputStream out) throws DataFetchException
Description copied from interface:DataFetcherCopies the content of a givenInputStreaminto a givenOutputStream.See
DataFetcher.copy(InputStream, OutputStream, boolean, boolean)for the handling of missing or invalid arguments.- Specified by:
copyin interfaceDataFetcher- Parameters:
in- TheInputStreamto read from.out- TheOutputStreamto write to.- Throws:
DataFetchException- If anything went wrong while reading from the givenInputStreamor writing to the givenOutputStream.
-
copy
public final void copy(InputStream in, OutputStream out, boolean closeIn, boolean closeOut) throws DataFetchException
Description copied from interface:DataFetcherCopies the content of a givenInputStreaminto a givenOutputStream.Missing or invalid arguments are handled gracefully with the following behaviour.
A
nullis given as anInputStream, it is simply ignored and handled as if there was nothing to read. IfcloseOutis true, the givenOutputStreamwill be closed anywayA
nullis given as anOutputStream, it is simply ignored, but the content of givenInputStreamis fetched anyway. IfcloseInis true, the givenInputStreamwill be closed anyway- Specified by:
copyin interfaceDataFetcher- Parameters:
in- TheInputStreamto read from.out- TheOutputStreamto write to.closeIn- Whether to close the givenInputStream, after reading from it.closeOut- Whether to close the givenOutputStream, after writing to it.- Throws:
DataFetchException- If anything went wrong while reading from the givenInputStreamor writing to the givenOutputStream.FetchExceptionsthrown while trying to close one of the given streams, if requested, are ignored.
-
copy
public final void copy(InputStream in, OutputStream out, DataFetchProgressListener listener) throws DataFetchException
Description copied from interface:DataFetcherCopies the content of a givenInputStreaminto a givenOutputStream.See
DataFetcher.copy(InputStream, OutputStream, boolean, boolean)for the handling of missing or invalid arguments.- Specified by:
copyin interfaceDataFetcher- Parameters:
in- TheInputStreamto read from.out- TheOutputStreamto write to.listener- TheDataFetchProgressListenerto report to.- Throws:
DataFetchException- If anything went wrong while reading from the givenInputStreamor writing to the givenOutputStream.
-
copy
public final void copy(InputStream in, OutputStream out, DataFetchProgressListener listener, boolean closeIn, boolean closeOut) throws DataFetchException
Description copied from interface:DataFetcherCopies the content of a givenInputStreaminto a givenOutputStream.Missing or invalid arguments are handled gracefully with the following behaviour.
A
nullis given as anInputStream, it is simply ignored and handled as if there was nothing to read. IfcloseOutis true, the givenOutputStreamwill be closed anywayA
nullis given as anOutputStream, it is simply ignored, but the content of givenInputStreamis fetched anyway. IfcloseInis true, the givenInputStreamwill be closed anyway- Specified by:
copyin interfaceDataFetcher- Parameters:
in- TheInputStreamto read from.out- TheOutputStreamto write to.listener- TheDataFetchProgressListenerto report to.closeIn- Whether to close the givenInputStream, after reading from it.closeOut- Whether to close the givenOutputStream, after writing to it.- Throws:
DataFetchException- If anything went wrong while reading from the givenInputStreamor writing to the givenOutputStream.FetchExceptionsthrown while trying to close one of the given streams, if requested, are ignored.
-
doCopy
protected abstract void doCopy(InputStream in, OutputStream out, DataFetchProgressListener listener) throws DataFetchException
Copies the content of a givenInputStreaminto a givenOutputStream.It is guaranteed that neither the given
InputStreamnor the givenOutputStreamnor the givenDataFetchProgressListeneris null.Implementers must not close either of the given streams.
- Parameters:
in- TheInputStreamto read from.out- TheOutputStreamto write to.listener- TheDataFetchProgressListenerto report to.- Throws:
DataFetchException- If anything went wrong while reading from the givenInputStreamor writing to the givenOutputStream.
-
-