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.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description LocalFileAccessor(FileHandleFactory.FileToHandleFunction fileHandleCreator, File file)
Make a read-only accessor for a "local" file. -
Method Summary
Modifier and Type Method Description com.fishlib.base.log.LogOutput
append(com.fishlib.base.log.LogOutput logOutput)
File
getFile()
String
getImplementationName()
Get a name for the implementing class.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 unusedRequiredSize)
Request an up-to-date size value for the file data space backing this accessor.String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.illumon.iris.db.v2.locations.FileAccessor
force, getOffsetView, truncate, write
-
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 handlesfile
- 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 interfaceFileAccessor
- 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
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
-
getFile
-
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 final com.fishlib.base.log.LogOutput append(@NotNull com.fishlib.base.log.LogOutput logOutput)- Specified by:
append
in interfacecom.fishlib.base.log.LogOutputAppendable
-
toString
-