use

open fun <R> use(function: OutputChannel<T>.() -> R): R

Runs function against this channel, closeing it once function returns normally (not on exceptions).