Class OutputToInputStreamAdapter
java.lang.Object
java.io.InputStream
zeroecho.sdk.util.OutputToInputStreamAdapter
- All Implemented Interfaces:
Closeable, AutoCloseable
An abstract adapter that converts an
OutputStream-based
transformation (such as encryption or compression) into an
InputStream-based one. This class reads data from a given
InputStream (the previousInput), processes it through a
transformation OutputStream (e.g., encryption, compression), and
exposes the transformed data via the standard InputStream API.
Subclasses must initialize the transformationOut field with a proper
OutputStream that writes transformed data into the internal buffer
(baos). This initialization must be done after construction
and before any read operation, via a subclass- specific method such
as an initialize(...) method.
Subclass Contract
- Set
transformationOutto a validOutputStreamthat writes tobaos. - Do not call virtual methods like initialization from constructors.
- Call the initialization method before performing any reads.
- Author:
- Leo Galambos
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ByteArrayOutputStreamA buffer holding transformed data.protected final intBuffer size in bytes used by this instance.protected static final intDefault buffer size in bytes.protected final InputStreamThe original input stream containing untransformed data.protected OutputStreamThe output stream performing transformation and writing tobaos. -
Constructor Summary
ConstructorsConstructorDescriptionOutputToInputStreamAdapter(InputStream previousInput) Constructs a new adapter wrapping the specified input stream using the default buffer size.OutputToInputStreamAdapter(InputStream previousInput, int bufSize) Constructs a new adapter wrapping the specified input stream with a given buffer size for transformation output. -
Method Summary
Methods inherited from class InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
DEFAULT_BUF_SIZE
protected static final int DEFAULT_BUF_SIZEDefault buffer size in bytes. Typically set to 8 KB (8 * 1024 bytes).- See Also:
-
BUF_SIZE
protected final int BUF_SIZEBuffer size in bytes used by this instance. Initialized during object construction and remains constant. -
previousInput
The original input stream containing untransformed data. -
baos
A buffer holding transformed data. -
transformationOut
The output stream performing transformation and writing tobaos. Must be initialized by subclasses before use.
-
-
Constructor Details
-
OutputToInputStreamAdapter
Constructs a new adapter wrapping the specified input stream with a given buffer size for transformation output.- Parameters:
previousInput- The input stream to read untransformed data from.bufSize- The buffer size for the transformation output buffer.
-
OutputToInputStreamAdapter
Constructs a new adapter wrapping the specified input stream using the default buffer size.- Parameters:
previousInput- The input stream to read untransformed data from.
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-