一、前言
关于dcm4che-core-2.0.25.jar开源包org.dcm4che2.util.CloseUtils源码关闭工具类,分别对java.io.Closeable、java.net.Socket、java.net.ServerSocket、javax.imageio.stream.ImageInputStream、java.sql.Statement对象关闭释放操作,详细具体参见源码说明。
二、源码说明
package org.dcm4che2.util;@b@@b@import java.io.Closeable;@b@import java.io.IOException;@b@import java.net.ServerSocket;@b@import java.net.Socket;@b@import java.sql.SQLException;@b@import java.sql.Statement;@b@import javax.imageio.stream.ImageInputStream;@b@import org.slf4j.Logger;@b@import org.slf4j.LoggerFactory;@b@@b@public final class CloseUtils@b@{@b@ private static Logger LOG = LoggerFactory.getLogger(CloseUtils.class);@b@@b@ public static void safeClose(Closeable object)@b@ {@b@ try@b@ {@b@ if (object != null)@b@ object.close();@b@ }@b@ catch (IOException e) {@b@ log(object, e);@b@ }@b@ }@b@@b@ public static void safeClose(Socket socket)@b@ {@b@ try@b@ {@b@ if (socket != null)@b@ socket.close();@b@ }@b@ catch (IOException e) {@b@ log(socket, e);@b@ }@b@ }@b@@b@ public static void safeClose(ServerSocket socket)@b@ {@b@ try@b@ {@b@ if (socket != null)@b@ socket.close();@b@ }@b@ catch (IOException e) {@b@ log(socket, e);@b@ }@b@ }@b@@b@ public static void safeClose(ImageInputStream is)@b@ {@b@ try@b@ {@b@ if (is != null)@b@ is.close();@b@ }@b@ catch (IOException e) {@b@ log(is, e);@b@ }@b@ }@b@@b@ public static void safeClose(Statement statement)@b@ {@b@ try@b@ {@b@ if (statement != null)@b@ statement.close();@b@ }@b@ catch (SQLException e) {@b@ log(statement, e);@b@ }@b@ }@b@@b@ private static void log(Object object, Exception e) {@b@ LOG.warn("error closing " + object.getClass().getName() + ": " + object.toString(), e);@b@ }@b@}