Interface IHasByteArray

All Superinterfaces:
IHasInputStream, IHasInputStreamAndReader, IHasSize
All Known Implementing Classes:
ByteArrayInputStreamProvider, ByteArrayWrapper, ReadableResourceByteArray, ReadableResourceString

public interface IHasByteArray extends IHasSize, IHasInputStreamAndReader
Base interface for all objects owning a byte array.
Since:
9.1.3
Author:
Philip Helger
  • Method Details

    • isEmpty

      default boolean isEmpty()
      Specified by:
      isEmpty in interface IHasSize
      Returns:
      true if no items are present, false if at least a single item is present.
      See Also:
    • isNotEmpty

      default boolean isNotEmpty()
      Specified by:
      isNotEmpty in interface IHasSize
      Returns:
      true if at least one item is present, false if no item is present.
      See Also:
    • isCopy

      boolean isCopy()
      Returns:
      true if the contained byte array was copied in the constructor or not.
    • getAllBytes

      @Nonnull @ReturnsMutableCopy default byte[] getAllBytes()
      Returns:
      A copy of all bytes contained, from getOffset() for IHasSize.size() bytes. Never null.
    • bytes

      Returns:
      A reference to the contained byte array. Gives write access to the payload! Don't forget to apply getOffset() and IHasSize.size(). Never null.
    • isPartialArray

      default boolean isPartialArray()
      Returns:
      true if this object deals with a partial array that either has an offset or which is not completely used. Based on this method, some performance optimizations might be used to avoid copying data.
      Since:
      11.1.5
    • getOffset

      @Nonnegative int getOffset()
      Returns:
      The offset into the byte array to start reading. This is always 0 when copied. Must be ge; 0.
      See Also:
    • hasOffset

      default boolean hasOffset()
      Returns:
      true if an offset is present, false if not.
    • getInputStream

      @Nonnull default InputStream getInputStream()
      Description copied from interface: IHasInputStream
      Get the input stream to read from the object. Each time this method is called, a new InputStream needs to be created.
      Specified by:
      getInputStream in interface IHasInputStream
      Returns:
      null if resolving failed.
    • isReadMultiple

      default boolean isReadMultiple()
      Description copied from interface: IHasInputStream
      Check if the InputStream from IHasInputStream.getInputStream() and IHasInputStream.getBufferedInputStream() can be acquired more than once.
      Specified by:
      isReadMultiple in interface IHasInputStream
      Returns:
      true if the input stream can be acquired more than once, false if not.
    • writeTo

      default void writeTo(@Nonnull @WillNotClose OutputStream aOS) throws IOException
      Write the relevant part of the byte array onto the provided output stream.
      Parameters:
      aOS - The output stream to write to. May not be null.
      Throws:
      IOException - In case of a write error.
    • startsWith

      default boolean startsWith(@Nonnull byte[] aCmpBytes)
      Check if the passed byte array starts with the bytes of this object.
      Parameters:
      aCmpBytes - The bytes to compare to. May not be null.
      Returns:
      true if the passed bytes start with the bytes in this object.
    • getHexEncoded

      @Nonnull default String getHexEncoded()
      Returns:
      The hex encoded version of this string. Never null but maybe empty, if the underlying array length is empty.
    • getBytesAsString

      @Nonnull default String getBytesAsString(@Nonnull Charset aCharset)
      Parameters:
      aCharset - The character set to use. May not be null.
      Returns:
      The byte array converted to a String, honoring getOffset() and IHasSize.size().
      Since:
      10.1.3