一、前言
关于hudson-core源码中hudson.util.IOUtils工具类,集成apache的org.apache.commons.io.IOUtils类重写并实现了绝对路径判断isAbsolute、复制copy及目录创建mkdirs及指定size内容跳过skip。
二、源码说明
package hudson.util;@b@@b@import java.io.*;@b@import java.util.regex.Pattern;@b@ @b@public class IOUtils extends org.apache.commons.io.IOUtils {@b@ @b@ public static void drain(InputStream in) throws IOException {@b@ copy(in,new NullStream());@b@ in.close();@b@ }@b@@b@ public static void copy(File src, OutputStream out) throws IOException {@b@ FileInputStream in = new FileInputStream(src);@b@ try {@b@ copy(in,out);@b@ } finally {@b@ closeQuietly(in);@b@ }@b@ }@b@@b@ public static void copy(InputStream in, File out) throws IOException {@b@ FileOutputStream fos = new FileOutputStream(out);@b@ try {@b@ copy(in,fos);@b@ } finally {@b@ closeQuietly(fos);@b@ }@b@ }@b@@b@ @b@ public static File mkdirs(File dir) throws IOException {@b@ if(dir.mkdirs() || dir.exists())@b@ return dir;@b@@b@ // following Ant <mkdir> task to avoid possible race condition.@b@ try {@b@ Thread.sleep(10);@b@ } catch (InterruptedException e) {@b@ // ignore@b@ }@b@@b@ if (dir.mkdirs() || dir.exists())@b@ return dir;@b@@b@ throw new IOException("Failed to create a directory at "+dir);@b@ }@b@@b@ @b@ public static long skip(InputStream in, long size) throws IOException {@b@ return org.apache.commons.io.IOUtils.skip(in, size);@b@ }@b@@b@ @b@ public static File absolutize(File base, String path) {@b@ if (isAbsolute(path))@b@ return new File(path);@b@ return new File(base, path);@b@ }@b@ @b@ public static boolean isAbsolute(String path) {@b@ Pattern DRIVE_PATTERN = Pattern.compile("[A-Za-z]:[\\\\/].*");@b@ return path.startsWith("/") || DRIVE_PATTERN.matcher(path).matches();@b@ }@b@@b@ private static final byte[] SKIP_BUFFER = new byte[8192];@b@}