Class MemoryMappedFileUtils


  • public final class MemoryMappedFileUtils
    extends Object
    Author:
    royer
    • Constructor Detail

      • MemoryMappedFileUtils

        public MemoryMappedFileUtils()
    • Method Detail

      • map

        public static final long map​(FileChannel pFileChannel,
                                     MemoryMappedFileAccessMode pAccessMode,
                                     long pFilePosition,
                                     long pMappedRegionLength,
                                     boolean pExtendIfNeeded)
                              throws MemoryMapFileException
        Maps a region of a file.
        Parameters:
        pFileChannel - file channel
        pAccessMode - access mode
        pFilePosition - file position in bytes
        pMappedRegionLength - mapped region length
        pExtendIfNeeded - extend file length if needed (file not as long as request mapping length).
        Returns:
        mapped address
        Throws:
        MemoryMapFileException - thrown if problem occurs while mapping.
      • unmap

        public static final int unmap​(FileChannel pFileChannel,
                                      long pMemoryMapAddress,
                                      long pMappedRegionLength)
                               throws MemoryMapFileException
        Unmaps memory mapped file.
        Parameters:
        pFileChannel - file channel
        pMemoryMapAddress - mapped address
        pMappedRegionLength - mapped region length
        Returns:
        return code
        Throws:
        MemoryMapFileException - thrown if problem occurs while unmapping
      • filesize

        public static final long filesize​(FileChannel pFileChannel)
                                   throws IOException
        Returns the file size for a given file channel
        Parameters:
        pFileChannel - file channel
        Returns:
        file size in bytes
        Throws:
        IOException - exception
      • truncate

        public static final void truncate​(FileChannel pFileChannel,
                                          long pLength)
                                   throws IOException
        Truncates file for given file channel
        Parameters:
        pFileChannel - file channel
        pLength - truncation length
        Throws:
        IOException - thrown if problem while truncating file
      • bestMode

        public static MemoryMappedFileAccessMode bestMode​(StandardOpenOption[] pStandardOpenOption)
        Determines best access mode gigen standard open options.
        Parameters:
        pStandardOpenOption - standard open options
        Returns:
        best access mode