FileHandle

class FileHandle(val filename: A_String, val alignment: Int, val canRead: Boolean, val canWrite: Boolean, val channel: AsynchronousFileChannel)

A FileHandle is an abstraction which wraps an AsynchronousFileChannel with some additional information like filename and buffer alignment. It gets stuffed in a pojo in a property of the atom that serves as Avail's most basic view of a file handle. Sockets use a substantially similar technique.

In addition, the FileHandle weakly tracks which buffers need to be evicted from Avail's file buffer cache.

Author

Mark van Gulik

Parameters

filename

The name of the file.

alignment

The alignment by which to access the file.

canRead

Whether the file can be read.

canWrite

Whether the file can be written.

channel

The AsynchronousFileChannel with which to do reading and writing.

Constructors

Link copied to clipboard
constructor(filename: A_String, alignment: Int, canRead: Boolean, canWrite: Boolean, channel: AsynchronousFileChannel)

Construct a new file handle.

Properties

Link copied to clipboard

The buffer alignment for the file. Reading is only ever attempted on this file at buffer boundaries. There is a global file buffer cache, which is an LRUCache of buffers across all open files. Each buffer in the cache has a length exactly equal to that file handle's alignment. A file will often have a partial buffer at the end due to its size not being an integral multiple of the alignment. Such a partial buffer is always excluded from the global file buffer cache.

Link copied to clipboard

A weak set of BufferKeys pertaining to this file, for which there may be entries in the global. Since the buffer keys are specific to each FileHandle, they are removed from the cache explicitly when the file is closed. This weak set allows the cache removals to happen efficiently.

Link copied to clipboard

Whether this file can be read.

Link copied to clipboard

Whether this file can be written.

Link copied to clipboard

The underlying AsynchronousFileChannel through which input and/or output takes place.

Link copied to clipboard

The name of the file.