Class PlainBytes

java.lang.Object
zeroecho.sdk.content.builtin.PlainBytes
All Implemented Interfaces:
DataContent, PlainContent

public class PlainBytes extends Object implements PlainContent
An implementation of PlainContent that encapsulates a byte array. Provides read-only access to the content through an InputStream backed by the internal byte buffer. This class represents the start of a DataContent processing chain, thus it does not accept input from preceding content.
Author:
Leo Galambos
  • Field Details

    • buffer

      protected final byte[] buffer
      Byte array buffer that holds the raw data managed by this instance.
  • Constructor Details

    • PlainBytes

      public PlainBytes(byte[] buffer)
      Constructs a new PlainBytes instance by copying the provided byte array.
      Parameters:
      buffer - the byte array to wrap
    • PlainBytes

      protected PlainBytes(int length)
      Constructs a new PlainBytes instance with a buffer of the specified length.
      Parameters:
      length - the size of the internal byte buffer to allocate
      Throws:
      NegativeArraySizeException - if length is negative
  • Method Details

    • setInput

      public void setInput(DataContent input)
      Connects this content to the output of a previous stage in the pipeline.

      This method is used to supply the input data that this content will process (e.g., a PlainContent being encrypted, or an encrypted content being decrypted).

      PlainBytes represents the start of a DataContent chain and therefore must not have any input. Calling this method with a non-null argument will result in an exception.
      Specified by:
      setInput in interface DataContent
      Parameters:
      input - the preceding DataContent, which must be null
      Throws:
      IllegalArgumentException - if input is not null
    • getStream

      public InputStream getStream() throws IOException
      Returns an InputStream for reading the byte array.
      Specified by:
      getStream in interface DataContent
      Returns:
      a new ByteArrayInputStream
      Throws:
      IOException - if an I/O error occurs
    • toBytes

      public byte[] toBytes()
      Returns a copy of the internal byte buffer.
      Specified by:
      toBytes in interface DataContent
      Returns:
      a new byte array containing the data from the internal buffer