Class EncryptedFileIO

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Truncates current file to zero length and resets current file position to zero.
      void close()
      Closes current file.
      void force()
      Forces any updates of this file to be written to the storage device that contains it.
      void force​(boolean withMetadata)
      Forces any updates of this file to be written to the storage device that contains it.
      int getFileSystemBlockSize()
      long getSparseSize()
      MappedByteBuffer map​(int sizeBytes)
      Allocates memory mapped buffer for this file with given size.
      long position()
      Returns current file position.
      void position​(long newPosition)
      Sets new current file position.
      int punchHole​(long position, int len)
      int read​(byte[] buf, int off, int len)
      Reads a up to length bytes from this file into the buffer.
      int read​(ByteBuffer destBuf)
      Reads a sequence of bytes from this file into the destinationBuffer.
      int read​(ByteBuffer destBuf, long position)
      Reads a sequence of bytes from this file into the destinationBuffer starting from specified file position.
      int readFully​(byte[] buf, int off, int len)
      Reads a up to length bytes from this file into the buffer.
      int readFully​(ByteBuffer destBuf)
      Reads a sequence of bytes from this file into the destinationBuffer.
      int readFully​(ByteBuffer destBuf, long position)
      Reads a sequence of bytes from this file into the destinationBuffer starting from specified file position.
      long size()
      Returns current file size in bytes.
      int write​(byte[] buf, int off, int len)
      Writes length bytes from the buffer starting at offset off to this file.
      int write​(ByteBuffer srcBuf)
      Writes a sequence of bytes to this file from the sourceBuffer.
      int write​(ByteBuffer srcBuf, long position)
      Writes a sequence of bytes to this file from the sourceBuffer starting from specified file position
      int writeFully​(byte[] buf, int off, int len)
      Writes length bytes from the buffer starting at offset off to this file.
      int writeFully​(ByteBuffer srcBuf)
      Writes a sequence of bytes to this file from the sourceBuffer.
      int writeFully​(ByteBuffer srcBuf, long position)
      Writes a sequence of bytes to this file from the sourceBuffer starting from specified file position
    • Method Detail

      • getFileSystemBlockSize

        public int getFileSystemBlockSize()
        Specified by:
        getFileSystemBlockSize in interface FileIO
        Returns:
        File system block size or negative value if unknown.
      • punchHole

        public int punchHole​(long position,
                             int len)
        Specified by:
        punchHole in interface FileIO
        Parameters:
        position - Starting file position.
        len - Number of bytes to free.
        Returns:
        The actual freed size or negative value if not supported.
      • position

        public long position()
                      throws IOException
        Returns current file position.
        Specified by:
        position in interface FileIO
        Returns:
        Current file position, a non-negative integer counting the number of bytes from the beginning of the file to the current position.
        Throws:
        IOException - If some I/O error occurs.
      • position

        public void position​(long newPosition)
                      throws IOException
        Sets new current file position.
        Specified by:
        position in interface FileIO
        Parameters:
        newPosition - The new position, a non-negative integer counting the number of bytes from the beginning of the file.
        Throws:
        IOException - If some I/O error occurs.
      • read

        public int read​(ByteBuffer destBuf)
                 throws IOException
        Reads a sequence of bytes from this file into the destinationBuffer.
        Specified by:
        read in interface FileIO
        Parameters:
        destBuf - Destination byte buffer.
        Returns:
        Number of read bytes, or -1 if the given position is greater than or equal to the file's current size
        Throws:
        IOException - If some I/O error occurs.
      • readFully

        public int readFully​(ByteBuffer destBuf)
                      throws IOException
        Reads a sequence of bytes from this file into the destinationBuffer.
        Specified by:
        readFully in interface FileIO
        Parameters:
        destBuf - Destination byte buffer.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • read

        public int read​(ByteBuffer destBuf,
                        long position)
                 throws IOException
        Reads a sequence of bytes from this file into the destinationBuffer starting from specified file position.
        Specified by:
        read in interface FileIO
        Parameters:
        destBuf - Destination byte buffer.
        position - Starting position of file.
        Returns:
        Number of read bytes, possibly zero, or -1 if the given position is greater than or equal to the file's current size
        Throws:
        IOException - If some I/O error occurs.
      • readFully

        public int readFully​(ByteBuffer destBuf,
                             long position)
                      throws IOException
        Reads a sequence of bytes from this file into the destinationBuffer starting from specified file position.
        Specified by:
        readFully in interface FileIO
        Parameters:
        destBuf - Destination byte buffer.
        position - Starting position of file.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • read

        public int read​(byte[] buf,
                        int off,
                        int len)
                 throws IOException
        Reads a up to length bytes from this file into the buffer.
        Specified by:
        read in interface FileIO
        Parameters:
        buf - Destination byte array.
        off - The start offset in array b at which the data is written.
        len - Maximum number of bytes read.
        Returns:
        Number of read bytes.
        Throws:
        IOException - If some I/O error occurs.
      • readFully

        public int readFully​(byte[] buf,
                             int off,
                             int len)
                      throws IOException
        Reads a up to length bytes from this file into the buffer.
        Specified by:
        readFully in interface FileIO
        Parameters:
        buf - Destination byte array.
        off - The start offset in array b at which the data is written.
        len - Number of bytes read.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • write

        public int write​(ByteBuffer srcBuf)
                  throws IOException
        Writes a sequence of bytes to this file from the sourceBuffer.
        Specified by:
        write in interface FileIO
        Parameters:
        srcBuf - Source buffer.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • writeFully

        public int writeFully​(ByteBuffer srcBuf)
                       throws IOException
        Writes a sequence of bytes to this file from the sourceBuffer.
        Specified by:
        writeFully in interface FileIO
        Parameters:
        srcBuf - Source buffer.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • write

        public int write​(ByteBuffer srcBuf,
                         long position)
                  throws IOException
        Writes a sequence of bytes to this file from the sourceBuffer starting from specified file position
        Specified by:
        write in interface FileIO
        Parameters:
        srcBuf - Source buffer.
        position - Starting file position.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • writeFully

        public int writeFully​(ByteBuffer srcBuf,
                              long position)
                       throws IOException
        Writes a sequence of bytes to this file from the sourceBuffer starting from specified file position
        Specified by:
        writeFully in interface FileIO
        Parameters:
        srcBuf - Source buffer.
        position - Starting file position.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • write

        public int write​(byte[] buf,
                         int off,
                         int len)
                  throws IOException
        Writes length bytes from the buffer starting at offset off to this file.
        Specified by:
        write in interface FileIO
        Parameters:
        buf - Source byte array.
        off - Start offset in the buffer.
        len - Number of bytes to write.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • writeFully

        public int writeFully​(byte[] buf,
                              int off,
                              int len)
                       throws IOException
        Writes length bytes from the buffer starting at offset off to this file.
        Specified by:
        writeFully in interface FileIO
        Parameters:
        buf - Source byte array.
        off - Start offset in the buffer.
        len - Number of bytes to write.
        Returns:
        Number of written bytes.
        Throws:
        IOException - If some I/O error occurs.
      • map

        public MappedByteBuffer map​(int sizeBytes)
                             throws IOException
        Allocates memory mapped buffer for this file with given size.
        Specified by:
        map in interface FileIO
        Parameters:
        sizeBytes - Size of buffer.
        Returns:
        Instance of mapped byte buffer.
        Throws:
        IOException - If some I/O error occurs.
      • force

        public void force()
                   throws IOException
        Forces any updates of this file to be written to the storage device that contains it.
        Specified by:
        force in interface FileIO
        Throws:
        IOException - If some I/O error occurs.
      • force

        public void force​(boolean withMetadata)
                   throws IOException
        Forces any updates of this file to be written to the storage device that contains it.
        Specified by:
        force in interface FileIO
        Parameters:
        withMetadata - If true force also file metadata.
        Throws:
        IOException - If some I/O error occurs.
      • size

        public long size()
                  throws IOException
        Returns current file size in bytes.
        Specified by:
        size in interface FileIO
        Returns:
        File size.
        Throws:
        IOException - If some I/O error occurs.
      • clear

        public void clear()
                   throws IOException
        Truncates current file to zero length and resets current file position to zero.
        Specified by:
        clear in interface FileIO
        Throws:
        IOException - If some I/O error occurs.