Class PlainBytes
java.lang.Object
zeroecho.sdk.content.builtin.PlainBytes
- All Implemented Interfaces:
DataContent, 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 Summary
FieldsModifier and TypeFieldDescriptionprotected final byte[]Byte array buffer that holds the raw data managed by this instance.Fields inherited from interface DataContent
DEFAULT_MAX_READ_SIZE -
Constructor Summary
ConstructorsModifierConstructorDescriptionPlainBytes(byte[] buffer) Constructs a newPlainBytesinstance by copying the provided byte array.protectedPlainBytes(int length) Constructs a newPlainBytesinstance with a buffer of the specified length. -
Method Summary
Modifier and TypeMethodDescriptionReturns anInputStreamfor reading the byte array.voidsetInput(DataContent input) Connects this content to the output of a previous stage in the pipeline.byte[]toBytes()Returns a copy of the internal byte buffer.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataContent
toText
-
Field Details
-
buffer
protected final byte[] bufferByte array buffer that holds the raw data managed by this instance.
-
-
Constructor Details
-
PlainBytes
public PlainBytes(byte[] buffer) Constructs a newPlainBytesinstance by copying the provided byte array.- Parameters:
buffer- the byte array to wrap
-
PlainBytes
protected PlainBytes(int length) Constructs a newPlainBytesinstance with a buffer of the specified length.- Parameters:
length- the size of the internal byte buffer to allocate- Throws:
NegativeArraySizeException- iflengthis negative
-
-
Method Details
-
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).PlainBytesrepresents the start of aDataContentchain and therefore must not have any input. Calling this method with a non-nullargument will result in an exception.- Specified by:
setInputin interfaceDataContent- Parameters:
input- the precedingDataContent, which must benull- Throws:
IllegalArgumentException- ifinputis notnull
-
getStream
Returns anInputStreamfor reading the byte array.- Specified by:
getStreamin interfaceDataContent- 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:
toBytesin interfaceDataContent- Returns:
- a new byte array containing the data from the internal buffer
-