Class LocalFileAccessor

java.lang.Object
com.illumon.iris.db.util.file.FileHandleAccessor
com.illumon.iris.db.v2.locations.local.LocalFileAccessor
All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, FileAccessor, NamedImplementation
Direct Known Subclasses:
WritableLocalFileAccessor

public class LocalFileAccessor
extends FileHandleAccessor
implements FileAccessor

Wraps a file, and manages a handle into that file. Supports positional read access only.

TODO: Consider adding a maximum number of retries for each operation that might encounter a ClosedChannelException.

Note: We don't test handle.isOpen(), because it's expected that we will encounter closed handles very rarely.

Note: We could re-open after ClosedByInterruptException for the next call, but it seems better assume this accessor will be used again right away in such cases.

  • Constructor Details

    • LocalFileAccessor

      public LocalFileAccessor​(@NotNull FileHandleFactory.FileToHandleFunction fileHandleCreator, @NotNull File file)
      Make a read-only accessor for a "local" file.
      Parameters:
      fileHandleCreator - The function used to make file handles
      file - The abstract path name to wrap access to
  • Method Details

    • size

      public final long size​(long unusedRequiredSize)
      Description copied from interface: FileAccessor
      Request an up-to-date size value for the file data space backing this accessor.
      Specified by:
      size in interface FileAccessor
      Parameters:
      unusedRequiredSize - Hint about the minimum size the caller would like as a result
      Returns:
      The size of the file data space backing this accessor
    • read

      public final int read​(ByteBuffer buffer, long position)
      Description copied from interface: FileAccessor
      Fill the supplied buffer with data starting at the supplied offset (position) into this file accessor. A successful invocation will fill the buffer from buffer.position(), inclusive, to at least buffer.limit(), exclusive, possibly up to buffer.capacity(), exclusive.
      Specified by:
      read in interface FileAccessor
      Parameters:
      buffer - A buffer with state appropriate for a call to FileChannel.read()
      position - The start position in this file accessor's data space to read from
      Returns:
      The number of bytes read, or -1 on error
    • getFile

      public final File getFile()
    • getImplementationName

      public String getImplementationName()
      Description copied from interface: NamedImplementation

      Get a name for the implementing class. Useful for abstract classes that implement LogOutputAppendable or override toString.

      The default implementation is correct, but not suitable for high-frequency usage.

      Specified by:
      getImplementationName in interface NamedImplementation
      Returns:
      A name for the implementing class
    • append

      public final com.fishlib.base.log.LogOutput append​(@NotNull com.fishlib.base.log.LogOutput logOutput)
      Specified by:
      append in interface com.fishlib.base.log.LogOutputAppendable
    • toString

      public final String toString()
      Overrides:
      toString in class Object