Class ByteArrayInputStreamProvider

java.lang.Object
com.helger.base.io.streamprovider.ByteArrayInputStreamProvider
All Implemented Interfaces:
IHasSize, IHasByteArray, IHasInputStream, IHasInputStreamAndReader, IWriteToStream

public class ByteArrayInputStreamProvider extends Object implements IHasByteArray
An InputStream provider based on a byte array.
Author:
Philip Helger
  • Field Details

  • Constructor Details

    • ByteArrayInputStreamProvider

      public ByteArrayInputStreamProvider(byte @NonNull [] aData)
      Constructor using the entire byte array without copying.
      Parameters:
      aData - The byte data. May not be null.
    • ByteArrayInputStreamProvider

      public ByteArrayInputStreamProvider(byte @NonNull [] aData, boolean bCopyNeeded)
      Constructor using the entire byte array.
      Parameters:
      aData - The byte data. May not be null.
      bCopyNeeded - true if the data should be copied, false otherwise.
    • ByteArrayInputStreamProvider

      public ByteArrayInputStreamProvider(byte @NonNull [] aData, @Nonnegative int nOfs, @Nonnegative int nLen)
      Constructor using a portion of the byte array without copying.
      Parameters:
      aData - The byte data. May not be null.
      nOfs - Offset into the byte array. Must be ≥ 0.
      nLen - Length of bytes to use. Must be ≥ 0.
    • ByteArrayInputStreamProvider

      public ByteArrayInputStreamProvider(byte @NonNull [] aData, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bCopyNeeded)
      Constructor using a portion of the byte array.
      Parameters:
      aData - The byte data. May not be null.
      nOfs - Offset into the byte array. Must be ≥ 0.
      nLen - Length of bytes to use. Must be ≥ 0.
      bCopyNeeded - true if the data should be copied, false otherwise.
  • Method Details

    • isCopy

      public final boolean isCopy()
      Specified by:
      isCopy in interface IHasByteArray
      Returns:
      true if the contained byte array was copied in the constructor or not.
    • bytes

      @ReturnsMutableObject public final byte @NonNull [] bytes()
      Specified by:
      bytes in interface IHasByteArray
      Returns:
      A reference to the contained byte array. Gives write access to the payload! Don't forget to apply IHasByteArray.getOffset() and IHasSize.size(). Never null.
    • getOffset

      @Nonnegative public final int getOffset()
      Specified by:
      getOffset in interface IHasByteArray
      Returns:
      The offset into the byte array to start reading. This is always 0 when copied. Must be ge; 0.
      See Also:
    • size

      @Nonnegative public final int size()
      Specified by:
      size in interface IHasSize
      Returns:
      The number of contained elements. Always ≥ 0.
    • toString

      public String toString()
      Overrides:
      toString in class Object