This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 3ca05905e4c18d3f26ec4b3ae51167da84c4619a Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Aug 8 09:35:04 2021 -0400 Add PathUtils.getTempDirectory(). --- src/changes/changes.xml | 3 +++ src/main/java/org/apache/commons/io/file/PathUtils.java | 17 +++++++++++++---- .../java/org/apache/commons/io/file/PathUtilsTest.java | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index cb4af92..d15cd25 100644 --- a/src/changes/changes.xml +++ b/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. diff --git a/src/main/java/org/apache/commons/io/file/PathUtils.java b/src/main/java/org/apache/commons/io/file/PathUtils.java index f7b640c..f1075b9 100644 --- a/src/main/java/org/apache/commons/io/file/PathUtils.java +++ b/src/main/java/org/apache/commons/io/file/PathUtils.java @@ -60,6 +60,7 @@ import java.util.stream.Collectors; 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 final class PathUtils { */ 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); } /** @@ -697,6 +695,17 @@ public final class PathUtils { } /** + * 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)}. * diff --git a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java index f90b267..63f29bd 100644 --- a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java +++ b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java @@ -161,6 +161,12 @@ public class PathUtilsTest extends TestArguments { } @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));