Class ImmutableFileRepeatableInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
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
-
Constructor Summary
ConstructorsConstructorDescriptionImmutableFileRepeatableInputStream(File file, boolean autoDelete) Creates a new instance -
Method Summary
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ImmutableFileRepeatableInputStream
Creates a new instance- Parameters:
file- the File that contains the stream's contentsautoDelete- iftrue, the file will be deleted whenclose()is invoked.- Throws:
IllegalArgumentException- if the file cannot be found
-
-
Method Details
-
getFile
- Returns:
- The
Filebacking this stream
-
isAutoDelete
public boolean isAutoDelete()- Returns:
- Whether the file will be deleted upon
close()or not.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-