added a convenience method

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24596 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2009-12-14 18:01:43 +00:00
1 parent e1c2f1c39a
commit b3553d68cf
1 file changed
+25 -2
+25 -2
View File
@@ -1,11 +1,11 @@
package hudson.util;
import java.io.OutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
/**
* Adds more to commons-io.
@@ -31,4 +31,27 @@ public class IOUtils extends org.apache.commons.io.IOUtils {
closeQuietly(fos);
}
}
/**
* Ensures that the given directory exists (if not, it's created, including all the parent directories.)
*
* @return
* This method returns the 'dir' parameter so that the method call flows better.
*/
public static File mkdirs(File dir) throws IOException {
if(dir.mkdirs() || dir.exists())
return dir;
// following Ant <mkdir> task to avoid possible race condition.
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// ignore
}
if (dir.mkdirs() || dir.exists())
return dir;
throw new IOException("Failed to create a directory at "+dir);
}
}