au.csiro.pbdava.ssparkle.common.utils.LoanUtils.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of variant-spark_2.11 Show documentation
Show all versions of variant-spark_2.11 Show documentation
Genomic variants interpretation toolkit
The newest version!
package au.csiro.pbdava.ssparkle.common.utils
import java.io.Closeable
import scala.io.Source
object LoanUtils {
def withSource[R](src: Source)(func: Source => R): R = {
try {
func(src)
} finally {
src.close()
}
}
def withCloseable[C <: Closeable, R](cl: C)(func: C => R): R = {
try {
func(cl)
} finally {
if (cl != null) {
cl.close()
}
}
}
def withResource[C <: AutoCloseable, R](cl: C)(func: C => R): R = {
try {
func(cl)
} finally {
cl.close()
}
}
}