RFE 4735419: File.createTempDirectory() to create a temporary directory
Michal Conos
michal.conos at googlemail.com
Fri Mar 27 13:17:56 UTC 2009
Hi,
I'd like to work on this RFE:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4735419
It looks like an easy start if I want to contribute to openjdk. Customers
are
often using a "workaround" described in bug which contains a race.
My solution would be something like proposed bellow - but it'd be nice
if someone could guide me through the process since I'd like to work on more
RFEs.
Cheers,
Michal
-------------
diff --git a/src/share/classes/java/io/File.java
b/src/share/classes/java/io/File.java
--- a/src/share/classes/java/io/File.java
+++ b/src/share/classes/java/io/File.java
@@ -2041,6 +2041,42 @@ public class File
}
}
+ public static File createTempDirectory(String prefix, String suffix,
+ File directory)
+ throws IOException
+ {
+ if (prefix.length() < 3)
+ throw new IllegalArgumentException("Prefix string too short");
+ if (suffix == null)
+ suffix = ".tmp";
+
+ File tmpdir = (directory != null) ?
+ directory : TemporaryDirectory.valueAsFile;
+ SecurityManager sm = System.getSecurityManager();
+ File f;
+ do {
+ f = TemporaryDirectory.generateFile(prefix, suffix, tmpdir);
+ if (sm != null) {
+ try {
+ sm.checkWrite(f.getPath());
+ } catch (SecurityException se) {
+ // don't reveal temporary directory location
+ if (directory == null)
+ throw new SecurityException("Unable to create
temporary file");
+ throw se;
+ }
+ }
+ } while (!fs.createDirectory(f.getPath()));
+ return f;
+ }
+
+ public static File createTempDirectory(String prefix, String suffix)
+ throws IOException
+ {
+ return createTempDirectory(prefix, suffix, null);
+ }
+
+
/* -- Basic infrastructure -- */
/**
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20090327/793d9cb1/attachment.html>
More information about the core-libs-dev
mailing list