IOUtils

object IOUtils

Properties

Link copied to clipboard
const val UTF_8: String

UTF-8 charset string.

Functions

Link copied to clipboard
@JvmName(name = "applyToAllNullable")
fun <T> applyToAll(collection: Collection<T?>, consumer: IOConsumer<T>)

Applies the consumer to all non-null elements in the collection. If the consumer throws an exception for one element, that exception is re-thrown after applying to all elements, and later exceptions are suppressed.

fun <T> applyToAll(collection: Collection<T>, consumer: IOConsumer<T>)
Link copied to clipboard

Closes all given AutoCloseables. :contentReferenceoaicite:0{index=0}

fun close(vararg objects: AutoCloseable)

Closes all given AutoCloseables. Some of the objects may be null; they are ignored. After everything is closed, throws the first exception encountered, or completes normally if none.

@JvmName(name = "closeNullable")
fun close(vararg objects: AutoCloseable?)
Link copied to clipboard

Closes all given AutoCloseables, suppressing all thrown non-Error exceptions. :contentReferenceoaicite:1{index=1} Even if a VirtualMachineError (or equivalent fatal Error) is thrown, all given resources are closed.

fun closeWhileHandlingException(closable: Closeable)
@JvmName(name = "closeWhileHandlingExceptionNullable")
fun closeWhileHandlingException(vararg objects: AutoCloseable?)

Closes all given AutoCloseables, suppressing all thrown exceptions. Some of the objects may be null; they are ignored.

Link copied to clipboard

Deletes all given file names from a Directory. :contentReferenceoaicite:5{index=5} Some of the names may be null; they are ignored. After deletion, throws the first exception encountered (with others suppressed) if any failures occurred.

Link copied to clipboard
fun deleteFilesIfExist(files: Collection<Path>)

Deletes all given Paths if they exist. After deletion, throws the first exception encountered (others suppressed) if any deletion failed.

fun deleteFilesIfExist(vararg files: Path)

Deletes all given Paths if they exist. Some may be null; they are ignored. After deletion, throws the first exception encountered (others suppressed) if any deletion failed.

Link copied to clipboard
fun deleteFilesIgnoringExceptions(vararg files: Path)

Deletes all given Paths, suppressing all thrown IOExceptions. Some of the paths may be null; they are ignored.

Deletes all given files in a Directory, suppressing all thrown IOExceptions. Note that the file names should not be null.

Deletes all given files in a Directory, suppressing all thrown IOExceptions. :contentReferenceoaicite:4{index=4}

Link copied to clipboard
fun fsync(fileToSync: Path, isDir: Boolean)

Ensure that any writes to the given file are persisted to the storage device. :contentReferenceoaicite:6{index=6} On non-JVM platforms, this is implemented as a no-op (except for checking file existence) since fsync is not universally available.

Link copied to clipboard

Wrapping the given InputStream in a reader using a CharsetDecoder. Unlike Java's defaults this reader will throw an exception if your it detects the read charset doesn't match the expected Charset.

Link copied to clipboard
fun <T> requireResourceNonNull(resource: T?, name: String?): T?

Wrap all calls to Class.getResource or Class.getResourceAsStream using this method to enforce existence of the resource. This code works around those methods returning null to signal non-existence.

Link copied to clipboard
fun reThrow(th: Throwable?)

Rethrows the argument as IOException or RuntimeException if it's not null.

Link copied to clipboard

Always rethrows the given Throwable as an IOException or unchecked exception. This method never actually returns; its return type Error (or in this port, Nothing) is only to satisfy the compiler that no code follows.

Link copied to clipboard

Rethrows the argument unchecked (as is if it's an Error or RuntimeException, or wrapped in RuntimeException).

Link copied to clipboard
fun rm(vararg locations: Path)

Deletes one or more files or directories (and everything underneath them). If any file or sub-file cannot be removed, throws IOException with details.

Link copied to clipboard
fun <T : Throwable> useOrSuppress(first: T?, second: T): T