Package com.helger.commons.io.stream
Class HasInputStream
java.lang.Object
com.helger.commons.io.stream.HasInputStream
- All Implemented Interfaces:
IHasInputStream
Special implementation of
IHasInputStream with that has an
InputStream supplier that can be read more than once!- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionHasInputStream(Supplier<? extends InputStream> aISP, boolean bReadMultiple) Constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic IHasInputStreamcreate(byte[] aBytes) Get a special implementation ofIHasInputStreamfor byte array.static IHasInputStreamGet a special implementation ofIHasInputStreamforNonBlockingByteArrayOutputStream.final InputStreamGet the input stream to read from the object.final booleanCheck if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.static HasInputStreammultiple(Supplier<? extends InputStream> aISP) Create a new object with a supplier that can read multiple times.static HasInputStreamonce(Supplier<? extends InputStream> aISP) Create a new object with a supplier that can be read only once.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.commons.io.IHasInputStream
getBufferedInputStream, withBufferedInputStreamDo, withInputStreamDo
-
Constructor Details
-
HasInputStream
Constructor- Parameters:
aISP-InputStreamsupplier. May not benull.bReadMultiple-trueif the supplier can be invoked more than once (e.g. from a byte[]) orfalseif it can be invoked only once (e.g. from an open socket).
-
-
Method Details
-
isReadMultiple
public final boolean isReadMultiple()Description copied from interface:IHasInputStreamCheck if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.- Specified by:
isReadMultiplein interfaceIHasInputStream- Returns:
trueif the input stream can be acquired more than once,falseif not.
-
getInputStream
Description copied from interface:IHasInputStreamGet the input stream to read from the object. Each time this method is called, a newInputStreamneeds to be created.- Specified by:
getInputStreamin interfaceIHasInputStream- Returns:
nullif resolving failed.
-
toString
-
multiple
@Nonnull @ReturnsMutableCopy public static HasInputStream multiple(@Nonnull Supplier<? extends InputStream> aISP) Create a new object with a supplier that can read multiple times.- Parameters:
aISP-InputStreamprovider. May not benull.- Returns:
- Never
null.
-
once
@Nonnull @ReturnsMutableCopy public static HasInputStream once(@Nonnull Supplier<? extends InputStream> aISP) Create a new object with a supplier that can be read only once.- Parameters:
aISP-InputStreamprovider. May not benull.- Returns:
- Never
null.
-
create
@Nonnull @ReturnsMutableCopy public static IHasInputStream create(@Nonnull NonBlockingByteArrayOutputStream aBAOS) Get a special implementation ofIHasInputStreamforNonBlockingByteArrayOutputStream. This input stream can be read multiple times.- Parameters:
aBAOS- Source stream. May not benull.- Returns:
- Never
null. - Since:
- 9.2.1
-
create
Get a special implementation ofIHasInputStreamfor byte array. This input stream can be read multiple times.
Note: don't alter the byte array after passing it in. It is not copied for performance reasons.- Parameters:
aBytes- Source byte array. May not benull.- Returns:
- Never
null. - Since:
- 11.2.0
-