au.csiro.sparkle.common.LoanUtils 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.sparkle.common;
import java.io.Closeable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.io.IOUtils;
public final class LoanUtils {
public static void withCloseable(final C in, ThrowingConsumer func) {
try {
func.accept(in);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
IOUtils.closeQuietly(in);
}
}
public static T withCloseableFunc(final C in, ThrowingFunction func) {
try {
return func.apply(in);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
IOUtils.closeQuietly(in);
}
}
public static void withPrintWriter(final File in, ThrowingConsumer func) {
try {
LoanUtils.withCloseable(new PrintWriter(new FileWriter(in)), func);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}