All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ebay.datameta.util.jdk.JdkUtil Maven / Gradle / Ivy

The newest version!
package org.ebay.datameta.util.jdk;

import javax.annotation.Nullable;
import java.io.Closeable;
import java.io.IOException;

/**
 * @author Michael Bergens
 */
public class JdkUtil {

    /**
     * Null-tolerant, non-disruptive close all call for the finally clause.
     *
     * @param errHandler error handler if any, see {@link CatchHandler}
     * @param closeables   to safely close (which by the way closes all related result sets) one by one, nulls ignored.
     * @deprecated Use Java 7'th try-with-resources instead.
     */
    @Api public void closeAll(@Nullable final CatchHandler errHandler, final Closeable... closeables) {
        for (Closeable closeable : closeables) {
            try {
                if (closeable != null) {
                    closeable.close();
                }
            }
            catch (IOException e) {
                if(errHandler != null) errHandler.handle(e);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy