package com.leanwo.activiti.util;

import java.io.Closeable;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 需关闭资源工具类
 * @author YangZhiJie
 *
 */
public class CloseableUtil {
	private final static Logger logger = LoggerFactory.getLogger(CloseableUtil.class);

	/**
	 * 关闭资源
	 * @param closeables
	 */
	public static void close(Closeable... closeables) {
		if (closeables != null && closeables.length > 0) {
			for (int i = 0; i < closeables.length; i++) {
				if (closeables[i] != null) {
					try {
						closeables[i].close();
					} catch (IOException e) {
						logger.error("资源释放失败", e);
					}
				}
			}
		}
	}
	
	/**
	 * 关闭资源
	 * @param closeables
	 */
	public static void close(AutoCloseable... closeables) {
		if(closeables != null && closeables.length > 0) {
			for(int i = 0; i < closeables.length ; i ++) {
				if(closeables[i] != null) {
					try {
						closeables[i].close();
					} catch (Exception e) {
						logger.error("资源释放失败", e);
					}
				}
			}
		}
	}
}
