Class ImmutableFileRepeatableInputStream

java.lang.Object
java.io.InputStream
org.mule.sdk.api.streaming.bytes.ImmutableFileRepeatableInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

@MinMuleVersion("4.5") @DoNotEnforceMinMuleVersion public final class ImmutableFileRepeatableInputStream extends InputStream
An InputStream implementation that allows obtaining a repeatable stream from the contents of an immutable file that already exists in the local file system.

The Mule Runtime is capable of generating larger than memory repeatable streams by buffering into a temporal file in the local file system. The problem with that approach is that when the contents of the original stream are already present in the file system, the temporary file is still created, consuming unnecessary disk space and IO time.

This class allows to generate an InputStream from a local file that the repeatable streaming engine will buffer from instead of generating a new one.

Immutability is a MANDATORY PRECONDITION for using this class. The file WILL NOT be modified by this class or the Mule streaming framework in any way. But at the same time, the file's immutability needs to be guaranteed, at least for the duration of this stream's lifecycle. This means that while the file is in use by instances of this class, no other process or thread can modify the file's content. Failing to meet this condition will result in dirty reads and content corruption. If this condition cannot be assured, then use a regular FileInputStream instead.

Also keep in mind that the purpose of this class is to optimize repeatable streaming resources on certain cases. However, in the context of a Mule application, the user can always decide to disable repeatable streaming, in which case, this stream will not be treated in a repeatable manner. The user can also configure an in-memory streaming strategy, in which case the behavior will be similar to using a FileInputStream.

Finally, notice that this stream is not auto closeable. close() method needs to be invoked explicitly.

Since:
1.0