且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Hadoop IOUtils closeStream方法看如何安全关闭流

更新时间:2021-11-05 11:11:21

使用方法

IOUtils.closeStream(writer);

进入代码

public static void closeStream(java.io.Closeable stream) {
	cleanup(null, stream);
}

public static void cleanup(Log log, java.io.Closeable... closeables) {
  for (java.io.Closeable c : closeables) {
    if (c != null) {
      try {
        c.close();
      } catch(IOException e) {
        if (log != null && log.isDebugEnabled()) {
          log.debug("Exception in closing " + c, e);
        }
      }
    }
  }
}