Package libcore.io
Class MemoryMappedFile
java.lang.Object
libcore.io.MemoryMappedFile
- All Implemented Interfaces:
AutoCloseable
public final class MemoryMappedFile extends Object implements AutoCloseable
A memory-mapped file. Use
#mmap to map a file, close() to unmap a file,
and either bigEndianIterator() or littleEndianIterator() to get a seekable
BufferIterator over the mapped data.-
Constructor Summary
Constructors Constructor Description MemoryMappedFile(long address, long size)Use this if you've calledmmapyourself. -
Method Summary
Modifier and Type Method Description BufferIteratorbigEndianIterator()Returns a new iterator that treats the mapped data as big-endian.voidclose()Unmaps this memory-mapped file using munmap(2).BufferIteratorlittleEndianIterator()Returns a new iterator that treats the mapped data as little-endian.static MemoryMappedFilemmapRO(String path)Use this to mmap the whole file read-only.longsize()Returns the size in bytes of the memory-mapped region.
-
Constructor Details
-
MemoryMappedFile
public MemoryMappedFile(long address, long size)Use this if you've calledmmapyourself.
-
-
Method Details
-
mmapRO
Use this to mmap the whole file read-only.- Throws:
ErrnoException
-
close
Unmaps this memory-mapped file using munmap(2). This is a no-op if close has already been called. Note that this class does not use finalization; you must callcloseyourself. Calling this method invalidates any iterators over thisMemoryMappedFile. It is an error to use such an iterator after callingclose.- Specified by:
closein interfaceAutoCloseable- Throws:
ErrnoException
-
bigEndianIterator
Returns a new iterator that treats the mapped data as big-endian. -
littleEndianIterator
Returns a new iterator that treats the mapped data as little-endian. -
size
public long size()Returns the size in bytes of the memory-mapped region.
-