FileHandle

abstract class FileHandle : Closeable

An open file for reading and writing; using either streaming and random access.

Use read and write to perform one-off random-access reads and writes. Use source, sink, and appendingSink for streaming reads and writes.

File handles must be closed when they are no longer needed. It is an error to read, write, or create streams after a file handle is closed. The operating system resources held by a file handle will be released once the file handle and all of its streams are closed.

Although this class offers both reading and writing APIs, file handle instances may be read-only or write-only. For example, a handle to a file on a read-only file system will throw an exception if a write is attempted.

File handles may be used by multiple threads concurrently. But the individual sources and sinks produced by a file handle are not safe for concurrent use.

Constructors

FileHandle
Link copied to clipboard
common
fun FileHandle()

Functions

appendingSink
Link copied to clipboard
common
fun appendingSink(): Sink
Returns a sink that writes to this starting at the end.
close
Link copied to clipboard
common
override fun close()
Closes this object and releases the resources it holds.
equals
Link copied to clipboard
common
open operator fun equals(other: Any?): Boolean
flush
Link copied to clipboard
common
fun flush()
Pushes all buffered bytes to their final destination.
hashCode
Link copied to clipboard
common
open fun hashCode(): Int
position
Link copied to clipboard
common
fun position(sink: Sink): Long
Returns the position of sink in the file.
fun position(source: Source): Long
Returns the position of source in the file.
read
Link copied to clipboard
common
fun read(fileOffset: Long, sink: Buffer, byteCount: Long): Long
Reads at least 1, and up to byteCount bytes from this starting at fileOffset and appends them to sink.
fun read(fileOffset: Long, array: ByteArray, arrayOffset: Int, byteCount: Int): Int
Reads at least 1, and up to byteCount bytes from this starting at fileOffset and copies them to array at arrayOffset.
resize
Link copied to clipboard
common
abstract fun resize(size: Long)
Changes the number of bytes in this file to size.
sink
Link copied to clipboard
common
fun sink(fileOffset: Long = 0L): Sink
Returns a sink that writes to this starting at fileOffset.
size
Link copied to clipboard
common
abstract fun size(): Long
Returns the total number of bytes in the file.
source
Link copied to clipboard
common
fun source(fileOffset: Long = 0L): Source
Returns a source that reads from this starting at fileOffset.
toString
Link copied to clipboard
common
open fun toString(): String
write
Link copied to clipboard
common
fun write(fileOffset: Long, source: Buffer, byteCount: Long)
Removes byteCount bytes from source and writes them to this at fileOffset.
fun write(fileOffset: Long, array: ByteArray, arrayOffset: Int, byteCount: Int)
Reads byteCount bytes from array and writes them to this at fileOffset.