use

inline fun <T : Closeable?, R> T.use(block: (T) -> R): R(source)

Executes the given block function on this resource and then closes it down correctly, whether an exception is thrown or not.

In case if the resource is being closed due to an exception throw within block, exceptions thrown by Closeable.close will be added as a suppressed exception instead of being thrown.

Return

The result of the block function.

Parameters

block

The function to process this Closeable resource.