Interface StreamCache


public interface StreamCache
Tagging interface to indicate that a type is capable of caching the underlying data stream.

This is a useful feature for avoiding message re-readability issues. This interface is mainly used by the StreamCachingStrategy for determining if/how to wrap a stream-based message.

The Camel routing engine uses the org.apache.camel.processor.CamelInternalProcessor.StreamCachingAdvice to apply the stream cache during routing.

It is recommended in the copy(Exchange) method to let the copied stream start from the start. If the implementation does not support copy, then return null.

Important: All the classes from the Camel release that implements StreamCache is NOT intended for end users to create as instances, but they are part of Camels stream-caching functionality.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
     
  • Method Summary

    Modifier and Type
    Method
    Description
    copy(Exchange exchange)
    Create a copy of the stream.
    boolean
    Whether this StreamCache is in memory only or spooled to persistent storage such as files.
    long
    Gets the length of the cached stream.
    long
    Read position
    void
    Resets the StreamCache for a new stream consumption.
    void
    Writes the stream to the given output
  • Field Details

  • Method Details

    • reset

      void reset()
      Resets the StreamCache for a new stream consumption.
    • writeTo

      void writeTo(OutputStream os) throws IOException
      Writes the stream to the given output
      Parameters:
      os - the destination to write to
      Throws:
      IOException - is thrown if write fails
    • copy

      StreamCache copy(Exchange exchange) throws IOException
      Create a copy of the stream. If possible use the same cached data in the copied instance.

      This method is useful for parallel processing.

      Implementations note: A copy of the stream is recommended to read from the start of the stream.

      Parameters:
      exchange - exchange in which the stream cache object is used; can be used to delete resources of the stream cache when the exchange is completed
      Returns:
      a copy, or null if copy is not possible
      Throws:
      IOException - is thrown if the copy fails
    • inMemory

      boolean inMemory()
      Whether this StreamCache is in memory only or spooled to persistent storage such as files.
    • length

      long length()
      Gets the length of the cached stream.

      The implementation may return 0 in cases where the length cannot be computed, or if the implementation does not support this.

      Returns:
      number of bytes in the cache.
    • position

      long position()
      Read position
      Returns:
      position or -1 if not supported in the cached implementation