Class ReadableResourceByteArray

java.lang.Object
com.helger.io.resource.inmemory.AbstractMemoryReadableResource
com.helger.io.resource.inmemory.ReadableResourceByteArray
All Implemented Interfaces:
com.helger.base.iface.IHasSize, com.helger.base.io.iface.IHasByteArray, com.helger.base.io.iface.IHasInputStream, com.helger.base.io.iface.IHasInputStreamAndReader, com.helger.base.io.iface.IWriteToStream, IMemoryReadableResource, IReadableResource, IResourceBase
Direct Known Subclasses:
ReadableResourceString

public class ReadableResourceByteArray extends AbstractMemoryReadableResource implements com.helger.base.io.iface.IHasByteArray
An in-memory IReadableResource based on a byte array.
Author:
Philip Helger
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ReadableResourceByteArray(byte @NonNull [] aBytes)
    Constructor using the full byte array with default copy behavior.
    ReadableResourceByteArray(byte @NonNull [] aBytes, boolean bCopyNeeded)
    Constructor using the full byte array with explicit copy behavior.
    ReadableResourceByteArray(byte @NonNull [] aBytes, int nOfs, int nLen)
    Constructor using a sub-range of the byte array with default copy behavior.
    ReadableResourceByteArray(byte @NonNull [] aBytes, int nOfs, int nLen, boolean bCopyNeeded)
    Constructor using a sub-range of the byte array with explicit copy behavior.
    ReadableResourceByteArray(@Nullable String sResourceID, byte @NonNull [] aBytes)
    Constructor with resource ID using the full byte array with default copy behavior.
    ReadableResourceByteArray(@Nullable String sResourceID, byte @NonNull [] aBytes, boolean bCopyNeeded)
    Constructor with resource ID using the full byte array with explicit copy behavior.
    ReadableResourceByteArray(@Nullable String sResourceID, byte @NonNull [] aBytes, int nOfs, int nLen)
    Constructor with resource ID using a sub-range with default copy behavior.
    ReadableResourceByteArray(@Nullable String sResourceID, byte @NonNull [] aBytes, int nOfs, int nLen, boolean bCopyNeeded)
    Full constructor with resource ID, sub-range and explicit copy behavior.
  • Method Summary

    Modifier and Type
    Method
    Description
    final byte @NonNull []
    @NonNull InputStream
     
    int
    final boolean
     
    boolean
     
    boolean
     
    final int
     

    Methods inherited from class com.helger.io.resource.inmemory.AbstractMemoryReadableResource

    exists, getAsFile, getAsURL, getPath, getReadableCloneForPath, getResourceID, setPath

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.helger.base.io.iface.IHasByteArray

    getAllBytes, getBytesAsString, getHexEncoded, hasOffset, isNotEmpty, isPartialArray, startsWith, writeTo

    Methods inherited from interface com.helger.base.io.iface.IHasInputStream

    getBufferedInputStream, withBufferedInputStreamDo, withInputStreamDo

    Methods inherited from interface com.helger.base.io.iface.IHasInputStreamAndReader

    getBufferedReader, getReader

    Methods inherited from interface com.helger.base.io.iface.IWriteToStream

    writeToAndClose
  • Field Details

  • Constructor Details

    • ReadableResourceByteArray

      public ReadableResourceByteArray(byte @NonNull [] aBytes)
      Constructor using the full byte array with default copy behavior.
      Parameters:
      aBytes - The byte array to use. May not be null.
    • ReadableResourceByteArray

      public ReadableResourceByteArray(byte @NonNull [] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen)
      Constructor using a sub-range of the byte array with default copy behavior.
      Parameters:
      aBytes - The byte array to use. May not be null.
      nOfs - The offset into the byte array. Must be ≥ 0.
      nLen - The number of bytes to use. Must be ≥ 0.
    • ReadableResourceByteArray

      public ReadableResourceByteArray(byte @NonNull [] aBytes, boolean bCopyNeeded)
      Constructor using the full byte array with explicit copy behavior.
      Parameters:
      aBytes - The byte array to use. May not be null.
      bCopyNeeded - true if a copy of the byte array should be made, false to use it directly.
    • ReadableResourceByteArray

      public ReadableResourceByteArray(byte @NonNull [] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bCopyNeeded)
      Constructor using a sub-range of the byte array with explicit copy behavior.
      Parameters:
      aBytes - The byte array to use. May not be null.
      nOfs - The offset into the byte array. Must be ≥ 0.
      nLen - The number of bytes to use. Must be ≥ 0.
      bCopyNeeded - true if a copy of the byte array should be made, false to use it directly.
    • ReadableResourceByteArray

      public ReadableResourceByteArray(@Nullable String sResourceID, byte @NonNull [] aBytes)
      Constructor with resource ID using the full byte array with default copy behavior.
      Parameters:
      sResourceID - The resource ID. May be null.
      aBytes - The byte array to use. May not be null.
    • ReadableResourceByteArray

      public ReadableResourceByteArray(@Nullable String sResourceID, byte @NonNull [] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen)
      Constructor with resource ID using a sub-range with default copy behavior.
      Parameters:
      sResourceID - The resource ID. May be null.
      aBytes - The byte array to use. May not be null.
      nOfs - The offset into the byte array. Must be ≥ 0.
      nLen - The number of bytes to use. Must be ≥ 0.
    • ReadableResourceByteArray

      public ReadableResourceByteArray(@Nullable String sResourceID, byte @NonNull [] aBytes, boolean bCopyNeeded)
      Constructor with resource ID using the full byte array with explicit copy behavior.
      Parameters:
      sResourceID - The resource ID. May be null.
      aBytes - The byte array to use. May not be null.
      bCopyNeeded - true if a copy of the byte array should be made, false to use it directly.
    • ReadableResourceByteArray

      public ReadableResourceByteArray(@Nullable String sResourceID, byte @NonNull [] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bCopyNeeded)
      Full constructor with resource ID, sub-range and explicit copy behavior.
      Parameters:
      sResourceID - The resource ID. May be null.
      aBytes - The byte array to use. May not be null.
      nOfs - The offset into the byte array. Must be ≥ 0.
      nLen - The number of bytes to use. Must be ≥ 0.
      bCopyNeeded - true if a copy of the byte array should be made, false to use it directly.
  • Method Details

    • isCopy

      public final boolean isCopy()
      Specified by:
      isCopy in interface com.helger.base.io.iface.IHasByteArray
      Returns:
      true if the internal byte array is a copy, false if the original reference is used.
    • bytes

      @ReturnsMutableObject public final byte @NonNull [] bytes()
      Specified by:
      bytes in interface com.helger.base.io.iface.IHasByteArray
    • getOffset

      @Nonnegative public int getOffset()
      Specified by:
      getOffset in interface com.helger.base.io.iface.IHasByteArray
    • size

      @Nonnegative public final int size()
      Specified by:
      size in interface com.helger.base.iface.IHasSize
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface com.helger.base.io.iface.IHasByteArray
      Specified by:
      isEmpty in interface com.helger.base.iface.IHasSize
    • getInputStream

      public @NonNull InputStream getInputStream()
      Specified by:
      getInputStream in interface com.helger.base.io.iface.IHasByteArray
      Specified by:
      getInputStream in interface com.helger.base.io.iface.IHasInputStream
    • isReadMultiple

      public boolean isReadMultiple()
      Specified by:
      isReadMultiple in interface com.helger.base.io.iface.IHasByteArray
      Specified by:
      isReadMultiple in interface com.helger.base.io.iface.IHasInputStream
    • toString

      public String toString()
      Overrides:
      toString in class AbstractMemoryReadableResource