Package com.illumon.iris.db.v2.locations
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
-
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.
-
Field Details
-
underlyingFileAccessor
-
startOffset
protected final long startOffset
-
-
Constructor Details
-
OffsetFileAccessor
- Parameters:
underlyingFileAccessor
- The file accessor to wrapstartOffset
- 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 interfaceFileAccessor
- 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
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 interfaceFileAccessor
- 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
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 interfaceFileAccessor
- 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 interfaceFileAccessor
- 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 interfaceFileAccessor
-
getOffsetView
Description copied from interface:FileAccessor
Get an offset view into this FileAccessor.- Specified by:
getOffsetView
in interfaceFileAccessor
- Parameters:
startOffset
- The offset- Returns:
- The new offset view accessor
-
getImplementationName
Description copied from interface:NamedImplementation
Get a name for the implementing class. Useful for abstract classes that implement
LogOutputAppendable
or overridetoString
.The default implementation is correct, but not suitable for high-frequency usage.
- Specified by:
getImplementationName
in interfaceNamedImplementation
- 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 interfacecom.fishlib.base.log.LogOutputAppendable
-
toString
-