Skip to content

Commit 5c1f21e

Browse files
committed
FileUtils: add shorter createTemporaryDirectory
This is nice, since suffix is allowed to be null.
1 parent 811112c commit 5c1f21e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/main/java/org/scijava/util/FileUtils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,30 @@ public static String limitPath(final String path, final int limit) {
397397
return new String(shortPathArray);
398398
}
399399

400+
/**
401+
* Creates a temporary directory.
402+
* <p>
403+
* Since there is no atomic operation to do that, we create a temporary file,
404+
* delete it and create a directory in its place. To avoid race conditions, we
405+
* use the optimistic approach: if the directory cannot be created, we try to
406+
* obtain a new temporary file rather than erroring out.
407+
* </p>
408+
* <p>
409+
* It is the caller's responsibility to make sure that the directory is
410+
* deleted; see {@link #deleteRecursively(File)}.
411+
* </p>
412+
*
413+
* @param prefix The prefix string to be used in generating the file's name;
414+
* see {@link File#createTempFile(String, String, File)}
415+
* @return An abstract pathname denoting a newly-created empty directory
416+
* @throws IOException
417+
*/
418+
public static File createTemporaryDirectory(final String prefix)
419+
throws IOException
420+
{
421+
return createTemporaryDirectory(prefix, null, null);
422+
}
423+
400424
/**
401425
* Creates a temporary directory.
402426
* <p>

0 commit comments

Comments
 (0)