Package org.apache.commons.io.input
Class MemoryMappedFileInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.io.input.AbstractInputStream
org.apache.commons.io.input.MemoryMappedFileInputStream
- All Implemented Interfaces:
- Closeable,- AutoCloseable
An 
InputStream that utilizes memory mapped files to improve performance. A sliding window of the file is
 mapped to memory to avoid mapping the entire file to memory at one time. The size of the sliding buffer is
 configurable.
 For most operating systems, mapping a file into memory is more expensive than reading or writing a few tens of kilobytes of data. From the standpoint of performance. it is generally only worth mapping relatively large files into memory.
 Note: Use of this class does not necessarily obviate the need to use a BufferedInputStream. Depending on the
 use case, the use of buffering may still further improve performance. For example:
 
 To build an instance, use MemoryMappedFileInputStream.Builder.
 
 BufferedInputStream s = new BufferedInputStream(new GzipInputStream(
   MemoryMappedFileInputStream.builder()
     .setPath(path)
     .setBufferSize(256 * 1024)
     .get()));
 should outperform:
new GzipInputStream(new MemoryMappedFileInputStream(path))
 GzipInputStream s = new GzipInputStream(
   MemoryMappedFileInputStream.builder()
     .setPath(path)
     .setBufferSize(256 * 1024)
     .get());
 - Since:
- 2.12.0
- See Also:
- 
Nested Class SummaryNested Classes
- 
Method SummaryMethods inherited from class org.apache.commons.io.input.AbstractInputStreamisClosed, setClosedMethods inherited from class java.io.InputStreammark, markSupported, read, reset
- 
Method Details- 
builderConstructs a newMemoryMappedFileInputStream.Builder.- Returns:
- a new MemoryMappedFileInputStream.Builder.
- Since:
- 2.12.0
 
- 
available- Overrides:
- availablein class- InputStream
- Throws:
- IOException
 
- 
close- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- AbstractInputStream
- Throws:
- IOException
 
- 
read- Specified by:
- readin class- InputStream
- Throws:
- IOException
 
- 
read- Overrides:
- readin class- InputStream
- Throws:
- IOException
 
- 
skip- Overrides:
- skipin class- InputStream
- Throws:
- IOException
 
 
-