/** * Functional try-with-resources: * * <pre>{@code * Try.with(() -> newIn(), () -> newOut()) * .run((from, to) -> copy(from, to)) * .onFailure(Throwable::printStacktrace); * }</pre> * * @param r1 Input resource. * @param r2 Input resource. * @param <R1> Resource type. * @param <R2> Resource type. * @return A resource handler. */ public final static <R1 extends AutoCloseable, R2 extends AutoCloseable> ResourceHandler2<R1, R2> with( Throwing.Supplier<R1> r1, Throwing.Supplier<R2> r2) { return new ResourceHandler2<>(r1, r2); }
private static void copy(final InputStream in, final OutputStream out) { Try.of(in, out) .run(ByteStreams::copy) .throwException(); }
private static void copy(final InputStream in, final OutputStream out) { Try.of(in, out) .run(ByteStreams::copy) .throwException(); }