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

gov.nasa.pds.registry.common.util.CloseUtils Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package gov.nasa.pds.registry.common.util;

import java.io.Closeable;
import java.util.stream.Stream;

import javax.xml.stream.XMLEventReader;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


/**
 * Utility class to close resources without throwing exceptions.
 * 
 * @author karpenko
 */
public class CloseUtils
{
    public static void close(Closeable cl)
    {
        if(cl == null) return;
        
        try
        {
            cl.close();
        }
        catch(Exception ex)
        {
            Logger log = LogManager.getLogger(CloseUtils.class);
            log.warn(ex);
        }
    }
    
    
    public static void close(XMLEventReader cl)
    {
        if(cl == null) return;
        
        try
        {
            cl.close();
        }
        catch(Exception ex)
        {
            Logger log = LogManager.getLogger(CloseUtils.class);
            log.warn(ex);
        }
    }


    public static void close(Stream cl)
    {
        if(cl == null) return;
        
        try
        {
            cl.close();
        }
        catch(Exception ex)
        {
            Logger log = LogManager.getLogger(CloseUtils.class);
            log.warn(ex);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy