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 Details

    • MemoryMappedFile

      public MemoryMappedFile​(long address, long size)
      Use this if you've called mmap yourself.
  • Method Details

    • 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 ErrnoException
      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 call close yourself. Calling this method invalidates any iterators over this MemoryMappedFile. It is an error to use such an iterator after calling close.
      Specified by:
      close in interface AutoCloseable
      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.