Interface DataContent

All Known Subinterfaces:
EncryptedContent, ExportableDataContent, MultiRecipientContent, PlainContent, SecretContent
All Known Implementing Classes:
AbstractExportableDataContent, PlainBytes, PlainFile, PlainString, SecretPassword

public interface DataContent
Represents a generic unit of data content. This may include plain, secret, or encrypted forms of data.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default maximum number of bytes that toBytes() will read.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an InputStream representing the content's data.
    default void
    Connects this content to the output of a previous stage in the pipeline.
    default byte[]
    Returns the content's data as a byte array, with a size limit of 16MB by default.
    default String
    Returns the content's data as a UTF-8 encoded string.
  • Field Details

    • DEFAULT_MAX_READ_SIZE

      static final int DEFAULT_MAX_READ_SIZE
      Default maximum number of bytes that toBytes() will read. This prevents accidental memory overload when reading large content into RAM.
      See Also:
  • Method Details

    • getStream

      InputStream getStream() throws IOException
      Returns an InputStream representing the content's data.

      The stream may be raw or transformed depending on the content type.

      Returns:
      input stream of the content; never null
      Throws:
      IOException - if an I/O error occurs opening the stream
    • toBytes

      default byte[] toBytes()
      Returns the content's data as a byte array, with a size limit of 16MB by default.

      This method is intended for small to medium-sized content. If the content exceeds DEFAULT_MAX_READ_SIZE, a IllegalStateException is thrown.

      Returns:
      the content data as byte[]
      Throws:
      RuntimeException - if reading from the stream fails
      IllegalStateException - if content exceeds allowed memory limit
    • toText

      default String toText()
      Returns the content's data as a UTF-8 encoded string.

      The default implementation converts toBytes() using UTF-8. Warning: This method is only safe if the content represents valid UTF-8 text. For arbitrary binary data (e.g., encrypted content), this may produce invalid or garbled output.

      Returns:
      the content data as String
      Throws:
      RuntimeException - if reading from the stream fails
      IllegalArgumentException - if the bytes are not valid UTF-8 (optional)
    • setInput

      default 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).

      Implementation Requirements:
      The default implementation of this method throws UnsupportedOperationException. Subclasses that support chaining must override this method.
      Parameters:
      input - the DataContent instance providing upstream data; may be null if this is the start of the pipeline
      Throws:
      UnsupportedOperationException - if not overridden by a subclass
      IllegalArgumentException - if the input is not allowed by the implementation