Class MappedRandomAccessFile

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class MappedRandomAccessFile
    extends java.lang.Object
    implements java.lang.AutoCloseable
    A MappedByteBuffer wrapped as a RandomAccessFile
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.channels.FileChannel channel  
      private java.nio.MappedByteBuffer mappedByteBuffer  
    • Constructor Summary

      Constructors 
      Constructor Description
      MappedRandomAccessFile​(java.lang.String filename, java.lang.String mode)
      Constructs a new MappedRandomAccessFile instance
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static boolean clean​(java.nio.ByteBuffer buffer)
      invokes the clean method on the ByteBuffer's cleaner
      private static boolean cleanJava11​(java.nio.ByteBuffer buffer)  
      void close()
      Cleans the mapped bytebuffer and closes the channel
      protected void finalize()
      Deprecated, for removal: This API element is subject to removal in a future version.
      java.nio.channels.FileChannel getChannel()  
      long getFilePointer()  
      private void init​(java.nio.channels.FileChannel channel, java.nio.channels.FileChannel.MapMode mapMode)
      initializes the channel and mapped bytebuffer
      long length()  
      int read()  
      int read​(byte[] bytes, int off, int len)  
      void seek​(long pos)  
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mappedByteBuffer

        private java.nio.MappedByteBuffer mappedByteBuffer
      • channel

        private java.nio.channels.FileChannel channel
    • Constructor Detail

      • MappedRandomAccessFile

        public MappedRandomAccessFile​(java.lang.String filename,
                                      java.lang.String mode)
                               throws java.io.IOException
        Constructs a new MappedRandomAccessFile instance
        Parameters:
        filename - String
        mode - String r, w or rw
        Throws:
        java.io.FileNotFoundException - on error
        java.io.IOException - on error
    • Method Detail

      • clean

        public static boolean clean​(java.nio.ByteBuffer buffer)
        invokes the clean method on the ByteBuffer's cleaner
        Parameters:
        buffer - ByteBuffer
        Returns:
        boolean true on success
      • cleanJava11

        private static boolean cleanJava11​(java.nio.ByteBuffer buffer)
      • init

        private void init​(java.nio.channels.FileChannel channel,
                          java.nio.channels.FileChannel.MapMode mapMode)
                   throws java.io.IOException
        initializes the channel and mapped bytebuffer
        Parameters:
        channel - FileChannel
        mapMode - FileChannel.MapMode
        Throws:
        java.io.IOException
      • getChannel

        public java.nio.channels.FileChannel getChannel()
        Returns:
        FileChannel
        Since:
        2.0.8
      • read

        public int read()
        Returns:
        int next integer or -1 on EOF
        See Also:
        RandomAccessFile.read()
      • read

        public int read​(byte[] bytes,
                        int off,
                        int len)
        Parameters:
        bytes - byte[]
        off - int offset
        len - int length
        Returns:
        int bytes read or -1 on EOF
        See Also:
        RandomAccessFile.read(byte[], int, int)
      • getFilePointer

        public long getFilePointer()
        Returns:
        long
        See Also:
        RandomAccessFile.getFilePointer()
      • seek

        public void seek​(long pos)
        Parameters:
        pos - long position
        See Also:
        RandomAccessFile.seek(long)
      • length

        public long length()
        Returns:
        long length
        See Also:
        RandomAccessFile.length()
      • close

        public void close()
                   throws java.io.IOException
        Cleans the mapped bytebuffer and closes the channel
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.io.IOException - on error
        See Also:
        RandomAccessFile.close()
      • finalize

        @Deprecated(since="OpenPDF-2.0.2",
                    forRemoval=true)
        protected void finalize()
                         throws java.lang.Throwable
        Deprecated, for removal: This API element is subject to removal in a future version.
        invokes the close method
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
        See Also:
        Object.finalize()