Package com.helger.commons.io.stream
Class StreamHelper.CopyByteStreamBuilder
- java.lang.Object
-
- com.helger.commons.io.stream.StreamHelper.CopyByteStreamBuilder
-
- Enclosing class:
- StreamHelper
public static class StreamHelper.CopyByteStreamBuilder extends Object implements IBuilder<ESuccess>
A simple builder to copy an InputStream (from(InputStream)) to an OutputStream (to(OutputStream)) with certain parameters. Callbuild()to execute the copying.- Since:
- 10.0.0
- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_CLOSE_DESTINATIONstatic booleanDEFAULT_CLOSE_SOURCE
-
Constructor Summary
Constructors Constructor Description CopyByteStreamBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StreamHelper.CopyByteStreamBuilderbuffer(byte[] a)ESuccessbuild()This method performs the main copyingStreamHelper.CopyByteStreamBuildercloseFrom(boolean b)StreamHelper.CopyByteStreamBuildercloseTo(boolean b)StreamHelper.CopyByteStreamBuildercopyByteCount(MutableLong a)StreamHelper.CopyByteStreamBuilderexceptionCallback(IExceptionCallback<IOException> a)StreamHelper.CopyByteStreamBuilderfrom(InputStream a)StreamHelper.CopyByteStreamBuilderlimit(long n)StreamHelper.CopyByteStreamBuilderlimit(Long a)StreamHelper.CopyByteStreamBuilderprogressCallback(LongConsumer a)StreamHelper.CopyByteStreamBuilderto(OutputStream a)StreamHelper.CopyByteStreamBuilderunlimited()Ensure no limit in copying (which is also the default).
-
-
-
Field Detail
-
DEFAULT_CLOSE_SOURCE
public static final boolean DEFAULT_CLOSE_SOURCE
- See Also:
- Constant Field Values
-
DEFAULT_CLOSE_DESTINATION
public static final boolean DEFAULT_CLOSE_DESTINATION
- See Also:
- Constant Field Values
-
-
Method Detail
-
from
@Nonnull public StreamHelper.CopyByteStreamBuilder from(@Nullable InputStream a)
- Parameters:
a- The InputStream to read from. May benull.- Returns:
- this for chaining
-
closeFrom
@Nonnull public StreamHelper.CopyByteStreamBuilder closeFrom(boolean b)
- Parameters:
b-trueto close the InputStream,falseto leave it open. Default isDEFAULT_CLOSE_SOURCE- Returns:
- this for chaining
-
to
@Nonnull public StreamHelper.CopyByteStreamBuilder to(@Nullable OutputStream a)
- Parameters:
a- The OutputStream to write to. May benull.- Returns:
- this for chaining
-
closeTo
@Nonnull public StreamHelper.CopyByteStreamBuilder closeTo(boolean b)
- Parameters:
b-trueto close the OutputStream,falseto leave it open.- Returns:
- this for chaining
-
buffer
@Nonnull public StreamHelper.CopyByteStreamBuilder buffer(@Nullable byte[] a)
- Parameters:
a- The buffer to use. May benull.- Returns:
- this for chaining
-
limit
@Nonnull public StreamHelper.CopyByteStreamBuilder limit(long n)
- Parameters:
n- An optional maximum number of bytes to copied from the InputStream to the OutputStream. May be < 0 to indicate no limit, meaning all bytes are copied.- Returns:
- this for chaining
- See Also:
unlimited()
-
limit
@Nonnull public StreamHelper.CopyByteStreamBuilder limit(@Nullable Long a)
- Parameters:
a- An optional maximum number of bytes to copied from the InputStream to the OutputStream. May be < 0 to indicate no limit, meaning all bytes are copied. Ifnullno limit is set- Returns:
- this for chaining
- Since:
- 10.1.0
- See Also:
unlimited()
-
unlimited
@Nonnull public StreamHelper.CopyByteStreamBuilder unlimited()
Ensure no limit in copying (which is also the default).- Returns:
- this for chaining
- See Also:
limit(long)
-
exceptionCallback
@Nonnull public StreamHelper.CopyByteStreamBuilder exceptionCallback(@Nullable IExceptionCallback<IOException> a)
- Parameters:
a- The Exception callback to be invoked, if an exception occurs. May benull.- Returns:
- this for chaining
-
copyByteCount
@Nonnull public StreamHelper.CopyByteStreamBuilder copyByteCount(@Nullable MutableLong a)
- Parameters:
a- An optional mutable long object that will receive the total number of copied bytes. Note: and optional old value is overwritten. Note: this is only called, if copying was successful, and not in case of an exception.- Returns:
- this for chaining
-
progressCallback
@Nonnull public StreamHelper.CopyByteStreamBuilder progressCallback(@Nullable LongConsumer a)
- Parameters:
a- An optional progress callback that takes the number of total bytes written during the copy action. It is first invoked after some byte were written.- Returns:
- this for chaining
- Since:
- 11.0.3
-
-