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
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of bytes thattoBytes()will read. -
Method Summary
Modifier and TypeMethodDescriptionReturns anInputStreamrepresenting the content's data.default voidsetInput(DataContent input) Connects this content to the output of a previous stage in the pipeline.default byte[]toBytes()Returns the content's data as a byte array, with a size limit of 16MB by default.default StringtoText()Returns the content's data as a UTF-8 encoded string.
-
Field Details
-
DEFAULT_MAX_READ_SIZE
static final int DEFAULT_MAX_READ_SIZEDefault maximum number of bytes thattoBytes()will read. This prevents accidental memory overload when reading large content into RAM.- See Also:
-
-
Method Details
-
getStream
Returns anInputStreamrepresenting 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, aIllegalStateExceptionis thrown.- Returns:
- the content data as
byte[] - Throws:
RuntimeException- if reading from the stream failsIllegalStateException- if content exceeds allowed memory limit
-
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 failsIllegalArgumentException- if the bytes are not valid UTF-8 (optional)
-
setInput
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
PlainContentbeing 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- theDataContentinstance providing upstream data; may benullif this is the start of the pipeline- Throws:
UnsupportedOperationException- if not overridden by a subclassIllegalArgumentException- if the input is not allowed by the implementation
-