Class StreamHelper.CopyByteStreamBuilder

java.lang.Object
com.helger.base.io.stream.StreamHelper.CopyByteStreamBuilder
All Implemented Interfaces:
IBuilder<ESuccess>
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. Call build() to execute the copying.
Since:
10.0.0
Author:
Philip Helger
  • Field Details

    • DEFAULT_CLOSE_SOURCE

      public static final boolean DEFAULT_CLOSE_SOURCE
      See Also:
    • DEFAULT_CLOSE_DESTINATION

      public static final boolean DEFAULT_CLOSE_DESTINATION
      See Also:
  • Constructor Details

    • CopyByteStreamBuilder

      public CopyByteStreamBuilder()
  • Method Details

    • from

      public @NonNull StreamHelper.CopyByteStreamBuilder from(@Nullable InputStream a)
      Parameters:
      a - The InputStream to read from. May be null.
      Returns:
      this for chaining
    • closeFrom

      public @NonNull StreamHelper.CopyByteStreamBuilder closeFrom(boolean b)
      Parameters:
      b - true to close the InputStream, false to leave it open. Default is DEFAULT_CLOSE_SOURCE
      Returns:
      this for chaining
    • to

      public @NonNull StreamHelper.CopyByteStreamBuilder to(@Nullable OutputStream a)
      Parameters:
      a - The OutputStream to write to. May be null.
      Returns:
      this for chaining
    • closeTo

      public @NonNull StreamHelper.CopyByteStreamBuilder closeTo(boolean b)
      Parameters:
      b - true to close the OutputStream, false to leave it open.
      Returns:
      this for chaining
    • buffer

      public @NonNull StreamHelper.CopyByteStreamBuilder buffer(byte @Nullable [] a)
      Parameters:
      a - The buffer to use. May be null.
      Returns:
      this for chaining
    • limit

      public @NonNull 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:
    • limit

      public @NonNull 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. If null no limit is set
      Returns:
      this for chaining
      Since:
      10.1.0
      See Also:
    • unlimited

      public @NonNull StreamHelper.CopyByteStreamBuilder unlimited()
      Ensure no limit in copying (which is also the default).
      Returns:
      this for chaining
      See Also:
    • exceptionCallback

      public @NonNull StreamHelper.CopyByteStreamBuilder exceptionCallback(@Nullable IExceptionCallback<IOException> a)
      Parameters:
      a - The Exception callback to be invoked, if an exception occurs. May be null.
      Returns:
      this for chaining
    • copyByteCount

      public @NonNull 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

      public @NonNull 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
    • build

      public @NonNull ESuccess build()
      This method performs the main copying
      Specified by:
      build in interface IBuilder<ESuccess>
      Returns:
      The built object. May not be null.