Package com.helger.commons.io
Interface IHasInputStream
- All Known Subinterfaces:
IHasByteArray,IHasInputStreamAndReader,IMemoryReadableResource,IReadableResource,IReadWriteResource,IWrappedReadableResource
- All Known Implementing Classes:
AbstractMemoryReadableResource,AbstractWrappedReadableResource,ByteArrayInputStreamProvider,ByteArrayWrapper,ByteBufferInputStreamProvider,CharsetHelper.InputStreamAndCharset,ClassPathResource,FileSystemResource,GZIPReadableResource,HasInputStream,ReadableResourceByteArray,ReadableResourceInputStream,ReadableResourceString,StringInputStreamProvider,URLResource
public interface IHasInputStream
A callback interface to retrieve
InputStream objects.- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptiondefault InputStreamGet a buffered input stream to read from the object.Get the input stream to read from the object.booleanCheck if theInputStreamfromgetInputStream()andgetBufferedInputStream()can be acquired more than once.default <T> TwithBufferedInputStreamDo(Function<InputStream, T> aFunc) Perform something with the bufferedInputStreamof this object and making sure, that it gets closed correctly afterwards.default <T> TwithInputStreamDo(Function<InputStream, T> aFunc) Perform something with theInputStreamof this object and making sure, that it gets closed correctly afterwards.
-
Method Details
-
getInputStream
Get the input stream to read from the object. Each time this method is called, a newInputStreamneeds to be created.- Returns:
nullif resolving failed.
-
getBufferedInputStream
Get a buffered input stream to read from the object. Each time this method is called, a newInputStreamneeds to be created. Internally invokesgetInputStream().- Returns:
nullif resolving failed.- Since:
- 9.1.8
-
withInputStreamDo
@Nullable default <T> T withInputStreamDo(@Nonnull Function<InputStream, T> aFunc) throws IOExceptionPerform something with theInputStreamof this object and making sure, that it gets closed correctly afterwards.- Type Parameters:
T- The result type of handling theInputStream- Parameters:
aFunc- The function to be invoked to read from theInputStream. This function needs to be able to deal with anull-parameter.- Returns:
- The result of the function. May be
null. - Throws:
IOException- In case reading from the InputStream fails- Since:
- 11.1.5
-
withBufferedInputStreamDo
@Nullable default <T> T withBufferedInputStreamDo(@Nonnull Function<InputStream, T> aFunc) throws IOExceptionPerform something with the bufferedInputStreamof this object and making sure, that it gets closed correctly afterwards.- Type Parameters:
T- The result type of handling the bufferedInputStream- Parameters:
aFunc- The function to be invoked to read from the bufferedInputStream. This function needs to be able to deal with anull-parameter.- Returns:
- The result of the function. May be
null. - Throws:
IOException- In case reading from the InputStream fails- Since:
- 11.1.5
-
isReadMultiple
boolean isReadMultiple()Check if theInputStreamfromgetInputStream()andgetBufferedInputStream()can be acquired more than once.- Returns:
trueif the input stream can be acquired more than once,falseif not.
-