一、前言
关于hudson-utils-2.1.2.jar源码包org.hudsonci.utils.io.Closer、org.hudsonci.utils.io.Flusher流关闭类及文本缓存处理类,分别基于java.io.Closeable接口流关闭处理、java.io.Flushable文本缓存刷新接口进行统一处理,详情参见源码说明。
package java.io;@b@...@b@public abstract class InputStream implements Closeable {@b@ ...@b@}
package java.io;@b@...@b@public abstract class Writer implements Appendable, Closeable, Flushable {@b@ ...@b@}
二、源码说明
1.Closer类
package org.hudsonci.utils.io;@b@@b@import java.io.Closeable;@b@import java.io.IOException;@b@import org.slf4j.Logger;@b@import org.slf4j.LoggerFactory;@b@@b@public class Closer@b@{@b@ private static final Logger log = LoggerFactory.getLogger(Closer.class);@b@@b@ public static void close(Closeable[] targets)@b@ {@b@ Closeable[] arr$;@b@ int i$;@b@ if (targets != null) {@b@ arr$ = targets; int len$ = arr$.length; for (i$ = 0; i$ < len$; ++i$) { Closeable c = arr$[i$];@b@ if (c == null)@b@ break label56:@b@@b@ try@b@ {@b@ c.close();@b@ }@b@ catch (IOException e) {@b@ log.trace(e.getMessage(), e);@b@ }@b@ }@b@ }@b@ label56:@b@ }@b@}
2.Flusher类
package org.hudsonci.utils.io;@b@@b@import java.io.Flushable;@b@import java.io.IOException;@b@import org.slf4j.Logger;@b@import org.slf4j.LoggerFactory;@b@@b@public class Flusher@b@{@b@ private static final Logger log = LoggerFactory.getLogger(Flusher.class);@b@@b@ public static void flush(Flushable[] targets)@b@ {@b@ Flushable[] arr$;@b@ int i$;@b@ if (targets != null) {@b@ arr$ = targets; int len$ = arr$.length; for (i$ = 0; i$ < len$; ++i$) { Flushable f = arr$[i$];@b@ if (f == null)@b@ break label56:@b@@b@ try@b@ {@b@ f.flush();@b@ }@b@ catch (IOException e) {@b@ log.trace(e.getMessage(), e);@b@ }@b@ }@b@ }@b@ label56:@b@ }@b@}