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 theStreamCachingStrategy
for determining if/how to wrap a stream-based message. The Camel routing engine uses theorg.apache.camel.processor.CamelInternalProcessor.StreamCachingAdvice
to apply the stream cache during routing. It is recommended in thecopy(Exchange)
method to let the copied stream start from the start. If the implementation does not support copy, then return null.
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_SPOOL_THRESHOLD
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StreamCache
copy(Exchange exchange)
Create a copy of the stream.boolean
inMemory()
Whether thisStreamCache
is in memory only or spooled to persistent storage such as files.long
length()
Gets the length of the cached stream.void
reset()
Resets the StreamCache for a new stream consumption.void
writeTo(OutputStream os)
Writes the stream to the given output
-
-
-
Field Detail
-
DEFAULT_SPOOL_THRESHOLD
static final long DEFAULT_SPOOL_THRESHOLD
- See Also:
- Constant Field Values
-
-
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 thisStreamCache
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.
-
-