ResilientPath

class ResilientPath(path: Path)

A wrapper around Path whose write operations retry on transient I/O failures.

Intended for paths that may live on a GCS-fuse mount, where close()-time uploads can fail with transient errors (e.g. "Stale file handle"). Read operations delegate directly to Path; mutating operations (writeText, createDirectories, deleteRecursively, etc.) wrap the call in an exponential-backoff retry loop. See writeText for the full rationale.

Constructors

Link copied to clipboard
constructor(path: String)

Constructs a ResilientPath from a string path, parsed via Path.of.

constructor(path: Path)

Types

Link copied to clipboard
object Companion

Factory helpers for constructing ResilientPath instances.

Properties

Link copied to clipboard

The normalized, absolute string form of this path.

Functions

Link copied to clipboard
fun createDirectories(maxRetries: Int = DEFAULT_MAX_RETRIES, initialDelayMs: Long = DEFAULT_INITIAL_DELAY_MS)

Retry-wrapped directory creation (including this path). See writeText for rationale.

Link copied to clipboard
fun createParentDirectories(maxRetries: Int = DEFAULT_MAX_RETRIES, initialDelayMs: Long = DEFAULT_INITIAL_DELAY_MS)

Retry-wrapped createParentDirectories. See writeText for rationale.

Link copied to clipboard
fun deleteIfExists(maxRetries: Int = DEFAULT_MAX_RETRIES, initialDelayMs: Long = DEFAULT_INITIAL_DELAY_MS)

Retry-wrapped deleteIfExists. See writeText for rationale.

Link copied to clipboard
fun deleteRecursively(maxRetries: Int = DEFAULT_MAX_RETRIES, initialDelayMs: Long = DEFAULT_INITIAL_DELAY_MS)

Retry-wrapped recursive delete. See writeText for rationale.

Link copied to clipboard
operator fun div(other: ResilientPath): ResilientPath
operator fun div(other: String): ResilientPath

Path-join operator, equivalent to resolve.

Link copied to clipboard

Whether the underlying path exists on the filesystem.

Link copied to clipboard
fun getPath(): Path

Returns the wrapped Path, bypassing the retry behavior; avoid unless strictly necessary.

Link copied to clipboard

Whether the path's file name has a .json extension (case-insensitive).

Link copied to clipboard

Reads the entire file content as text.

Link copied to clipboard

Resolves other against this path, returning a new ResilientPath.

Link copied to clipboard

Formats this path as a clickable file:// URI for log output, or file://<file not specified> when the receiver is null.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun writeText(text: String, maxRetries: Int = DEFAULT_MAX_RETRIES, initialDelayMs: Long = DEFAULT_INITIAL_DELAY_MS)

Writes text to this path with automatic retry on transient I/O failures.