Add PathUtils.getTempDirectory().
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -126,6 +126,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add and reuse UncheckedIOExceptions.
</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add PathUtils.getTempDirectory().
+ </action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.

MODIFY
src/main/java/org/apache/commons/io/file/PathUtils.java
src/main/java/org/apache/commons/io/file/PathUtils.java
import java.util.stream.Stream;
import org.apache.commons.io.Charsets;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOExceptionList;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.UncheckedIOExceptions;
@@ -300,10 +301,7 @@ public static PathCounters countDirectory(final Path directory) throws IOExcepti
*/
public static Path createParentDirectories(final Path path, final FileAttribute<?>... attrs) throws IOException {
final Path parent = path.getParent();
- if (parent == null) {
- return null;
- }
- return Files.createDirectories(parent, attrs);
+ return parent == null ? null : Files.createDirectories(parent, attrs);
}
/**
@@ -696,6 +694,17 @@ public static boolean fileContentEquals(final Path path1, final Path path2, fina
return fileAttributeView == null ? null : fileAttributeView.getAcl();
}
+ /**
+ * Returns a {@link Path} representing the system temporary directory.
+ *
+ * @return the system temporary directory.
+ *
+ * @since 2.12.0
+ */
+ public static Path getTempDirectory() {
+ return Paths.get(FileUtils.getTempDirectoryPath());
+ }
+
/**
* Tests whether the specified {@code Path} is a directory or not. Implemented as a null-safe delegate to
* {@code Files.isDirectory(Path path, LinkOption... options)}.

MODIFY
src/test/java/org/apache/commons/io/file/PathUtilsTest.java
src/test/java/org/apache/commons/io/file/PathUtilsTest.java
@@ -160,6 +160,12 @@ public void testCreateDirectoriesNew() throws IOException {
assertEquals(tempDir, PathUtils.createParentDirectories(tempDir.resolve("child")));
}
+ @Test
+ public void testGetTempDirectory() {
+ final Path tempDirectory = Paths.get(System.getProperty("java.io.tmpdir"));
+ assertEquals(tempDirectory, PathUtils.getTempDirectory());
+ }
+
@Test
public void testIsDirectory() throws IOException {
assertFalse(PathUtils.isDirectory(null));

Add PathUtils.getTempDirectory().