Interface DataStream


public interface DataStream
Core interface for handling data streams with automatic resource management. Provides a unified approach for: - Converting between stream and byte array representations - Managing stream resources safely - Supporting both reading and buffering operations - Ensuring proper cleanup of system resources Implementations should ensure proper resource cleanup through try-with-resources.
Author:
pchretien
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new input stream for reading the data content.
    default byte[]
    Returns the stream content as a byte array.
  • Method Details

    • getBytes

      default byte[] getBytes()
      Returns the stream content as a byte array. Automatically manages resource lifecycle: - Creates input stream - Buffers content efficiently - Ensures proper cleanup Uses a 16KB buffer for optimal performance.
      Returns:
      Content as byte array
      Throws:
      WrappedException - if an I/O error occurs during reading
    • createInputStream

      InputStream createInputStream() throws IOException
      Creates a new input stream for reading the data content. Each call returns a fresh stream instance that must be closed after use. Callers should use try-with-resources to ensure proper cleanup.
      Returns:
      New input stream instance for reading data
      Throws:
      IOException - If stream creation fails