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.

    • Method Detail

      • 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.