Class OffsetFileAccessor<UFAT extends FileAccessor>

java.lang.Object
com.illumon.iris.db.v2.locations.OffsetFileAccessor<UFAT>
All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, FileAccessor, NamedImplementation

public class OffsetFileAccessor<UFAT extends FileAccessor>
extends Object
implements FileAccessor
Wrap an underlying FileAccessor, providing an offset view into the underlying accessor's data. The offset view will be writable if and only if the underlying FileAccessor is writable.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected long startOffset  
    protected UFAT underlyingFileAccessor  

    Fields inherited from interface com.illumon.iris.db.v2.locations.FileAccessor

    NULL_REQUIRED_SIZE
  • Constructor Summary

    Constructors 
    Constructor Description
    OffsetFileAccessor​(UFAT underlyingFileAccessor, long startOffset)  
  • Method Summary

    Modifier and Type Method Description
    com.fishlib.base.log.LogOutput append​(com.fishlib.base.log.LogOutput logOutput)  
    void force()
    Make sure any previous writes to the underlying file through this file accessor are persisted, synchronously.
    String getImplementationName()
    Get a name for the implementing class.
    FileAccessor getOffsetView​(long startOffset)
    Get an offset view into this FileAccessor.
    int read​(ByteBuffer buffer, long position)
    Fill the supplied buffer with data starting at the supplied offset (position) into this file accessor.
    long size​(long requiredSize)
    Request an up-to-date size value for the file data space backing this accessor.
    String toString()  
    void truncate​(long size)
    Truncate the file data space backing this accessor to the supplied size.
    int write​(ByteBuffer buffer, long position)
    Write the supplied buffer (from buffer.position(), inclusive, to buffer.limit(), exclusive), starting at the supplied offset (position) into this file accessor.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • OffsetFileAccessor

      public OffsetFileAccessor​(@NotNull UFAT underlyingFileAccessor, long startOffset)
      Parameters:
      underlyingFileAccessor - The file accessor to wrap
      startOffset - The offset into the underlying file accessor's data
  • Method Details

    • size

      public long size​(long requiredSize)
      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:
      requiredSize - 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 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
    • write

      public int write​(@NotNull ByteBuffer buffer, long position)
      Description copied from interface: FileAccessor
      Write the supplied buffer (from buffer.position(), inclusive, to buffer.limit(), exclusive), starting at the supplied offset (position) into this file accessor.
      Specified by:
      write in interface FileAccessor
      Parameters:
      buffer - A buffer with state appropriate for a call to FileChannel.write()
      position - The start position in this file accessor's data space to write to
      Returns:
      The number of bytes written, or -1 on error
    • truncate

      public void truncate​(long size)
      Description copied from interface: FileAccessor
      Truncate the file data space backing this accessor to the supplied size.
      Specified by:
      truncate in interface FileAccessor
      Parameters:
      size - The new size
    • force

      public void force()
      Description copied from interface: FileAccessor
      Make sure any previous writes to the underlying file through this file accessor are persisted, synchronously.
      Specified by:
      force in interface FileAccessor
    • getOffsetView

      public FileAccessor getOffsetView​(long startOffset)
      Description copied from interface: FileAccessor
      Get an offset view into this FileAccessor.
      Specified by:
      getOffsetView in interface FileAccessor
      Parameters:
      startOffset - The offset
      Returns:
      The new offset view accessor
    • 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 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 String toString()
      Overrides:
      toString in class Object