Class OutputToInputStreamAdapter

java.lang.Object
java.io.InputStream
zeroecho.sdk.util.OutputToInputStreamAdapter
All Implemented Interfaces:
Closeable, AutoCloseable

public abstract class OutputToInputStreamAdapter extends InputStream
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 transformationOut to a valid OutputStream that writes to baos.
  • Do not call virtual methods like initialization from constructors.
  • Call the initialization method before performing any reads.
Author:
Leo Galambos
  • Field Details

    • DEFAULT_BUF_SIZE

      protected static final int DEFAULT_BUF_SIZE
      Default buffer size in bytes. Typically set to 8 KB (8 * 1024 bytes).
      See Also:
    • BUF_SIZE

      protected final int BUF_SIZE
      Buffer size in bytes used by this instance. Initialized during object construction and remains constant.
    • previousInput

      protected final InputStream previousInput
      The original input stream containing untransformed data.
    • baos

      protected ByteArrayOutputStream baos
      A buffer holding transformed data.
    • transformationOut

      protected OutputStream transformationOut
      The output stream performing transformation and writing to baos. Must be initialized by subclasses before use.
  • Constructor Details

    • OutputToInputStreamAdapter

      public OutputToInputStreamAdapter(InputStream previousInput, int bufSize)
      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

      public OutputToInputStreamAdapter(InputStream previousInput)
      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