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#mmapto map a file,close()to unmap a file, and eitherbigEndianIterator()orlittleEndianIterator()to get a seekableBufferIteratorover the mapped data.
-
-
Constructor Summary
Constructors Constructor Description MemoryMappedFile(long address, long size)Use this if you've calledmmapyourself.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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.
-
-
-
Method Detail
-
mmapRO
public static MemoryMappedFile mmapRO(String path) throws ErrnoException
Use this to mmap the whole file read-only.- Throws:
ErrnoException
-
close
public void close() throws ErrnoExceptionUnmaps 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
public BufferIterator bigEndianIterator()
Returns a new iterator that treats the mapped data as big-endian.
-
littleEndianIterator
public BufferIterator 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.
-
-