Package org.apache.camel
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
to
apply the stream cache during routing.
It is recommended in the
StreamCachingStrategy for determining if/how to wrap a stream-based message.
The Camel routing engine uses the
invalid reference
org.apache.camel.processor.CamelInternalProcessor.StreamCachingAdvice
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 -
Method Summary
Modifier and TypeMethodDescriptionCreate a copy of the stream.booleaninMemory()Whether thisStreamCacheis in memory only or spooled to persistent storage such as files.longlength()Gets the length of the cached stream.longposition()Read positionvoidreset()Resets the StreamCache for a new stream consumption.voidwriteTo(OutputStream os) Writes the stream to the given output
-
Field Details
-
DEFAULT_SPOOL_THRESHOLD
static final long DEFAULT_SPOOL_THRESHOLD- See Also:
-
-
Method Details
-
reset
void reset()Resets the StreamCache for a new stream consumption. -
writeTo
Writes the stream to the given output- Parameters:
os- the destination to write to- Throws:
IOException- is thrown if write fails
-
copy
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 thisStreamCacheis 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
-