Package ome.io.nio

Class FileBuffer


  • public class FileBuffer
    extends AbstractBuffer
    Raw file buffer which provides I/O operations within the OMERO file repository.
    Since:
    OMERO3.0
    • Constructor Summary

      Constructors 
      Constructor Description
      FileBuffer​(java.lang.String path, java.lang.String mode)
      Default constructor allowing to pass in a non-"rw" file mode.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the buffer, cleaning up file state.
      void flush​(boolean includeMetadata)
      Flush the buffer, writing any pending content to the underlying storage device, optionally also the file's metadata.
      java.lang.String getMode()
      Retrieves the current file mode
      int read​(java.nio.ByteBuffer dst)
      Delegates to FileChannel
      int read​(java.nio.ByteBuffer dst, long position)
      Delegates to FileChannel
      long size()  
      void truncate​(long size)  
      boolean truncateIfSmaller​(long size)
      Only truncate if the size of the file is less than the size argument.
      int write​(java.nio.ByteBuffer src)
      Delegates to FileChannel
      int write​(java.nio.ByteBuffer src, long position)
      Delegates to FileChannel
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FileBuffer

        public FileBuffer​(java.lang.String path,
                          java.lang.String mode)
        Default constructor allowing to pass in a non-"rw" file mode.
        Parameters:
        path - path to the root of the File repository.
        mode - will be passed to the constructor of RandomAccessFile
        Throws:
        java.io.FileNotFoundException
    • Method Detail

      • getMode

        public java.lang.String getMode()
        Retrieves the current file mode
        Returns:
        See above
      • close

        public void close()
                   throws java.io.IOException
        Closes the buffer, cleaning up file state.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • flush

        public void flush​(boolean includeMetadata)
                   throws java.io.IOException
        Flush the buffer, writing any pending content to the underlying storage device, optionally also the file's metadata.
        Parameters:
        includeMetadata - flushes also the file metadata, not just the content
        Throws:
        java.io.IOException - an I/O error that occurred
      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Delegates to FileChannel
        Throws:
        java.io.IOException
        See Also:
        FileChannel.read(ByteBuffer)
      • read

        public int read​(java.nio.ByteBuffer dst,
                        long position)
                 throws java.io.IOException
        Delegates to FileChannel
        Throws:
        java.io.IOException
        See Also:
        FileChannel.read(ByteBuffer, long)
      • write

        public int write​(java.nio.ByteBuffer src,
                         long position)
                  throws java.io.IOException
        Delegates to FileChannel
        Throws:
        java.io.IOException
        See Also:
        FileChannel.write(ByteBuffer, long)
      • write

        public int write​(java.nio.ByteBuffer src)
                  throws java.io.IOException
        Delegates to FileChannel
        Throws:
        java.io.IOException
        See Also:
        FileChannel.write(ByteBuffer)
      • size

        public long size()
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • truncate

        public void truncate​(long size)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • truncateIfSmaller

        public boolean truncateIfSmaller​(long size)
                                  throws java.io.IOException
        Only truncate if the size of the file is less than the size argument.
        Parameters:
        size -
        Returns:
        true if truncation was performed.
        Throws:
        java.io.IOException