Add PathUtils for operations on NIO Path.
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -146,6 +146,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-631" dev="ggregory" type="add" due-to="Gary Gregory">
Add a CountingFileVisitor (as the basis for a forthcoming DeletingFileVisitor).
</action>
+ <action issue="IO-632" dev="ggregory" type="add" due-to="Gary Gregory">
+ Add PathUtils for operations on NIO Path.
+ </action>
</release>
<release version="2.6" date="2017-10-15" description="Java 7 required, Java 9 supported.">

ADD
src/main/java/org/apache/commons/io/PathUtils.java
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.io;
+
+import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+/**
+ * NIO Path utilities.
+ *
+ * @since 2.7
+ */
+public class PathUtils {
+
+ /**
+ * Returns whether the given file or directory is empty.
+ *
+ * @param path the the given file or directory to query.
+ * @return whether the given file or directory is empty.
+ * @throws IOException if an I/O error occurs
+ */
+ public static boolean isEmpty(final Path path) throws IOException {
+ return Files.isDirectory(path) ? isEmptyDirectory(path) : isEmptyFile(path);
+ }
+
+ /**
+ * Returns whether the directory is empty.
+ *
+ * @param directory the the given directory to query.
+ * @return whether the given directory is empty.
+ * @throws IOException if an I/O error occurs
+ */
+ public static boolean isEmptyDirectory(final Path directory) throws IOException {
+ try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) {
+ if (directoryStream.iterator().hasNext()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns whether the given file is empty.
+ *
+ * @param file the the given file to query.
+ * @return whether the given file is empty.
+ * @throws IOException if an I/O error occurs
+ */
+ public static boolean isEmptyFile(final Path file) throws IOException {
+ return Files.size(file) <= 0;
+ }
+
+}

ADD
src/test/java/org/apache/commons/io/PathUtilsTest.java
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.io;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link PathUtils}.
+ */
+public class PathUtilsTest {
+
+ private static final Path DIR_SIZE_1 = Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1");
+
+ private static final Path FILE_SIZE_0 = Paths
+ .get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0/file-size-0.bin");
+
+ private static final Path FILE_SIZE_1 = Paths
+ .get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/file-size-1.bin");
+
+ @Test
+ public void testIsEmpty() throws IOException {
+ Assertions.assertTrue(PathUtils.isEmpty(FILE_SIZE_0));
+ Assertions.assertFalse(PathUtils.isEmpty(FILE_SIZE_1));
+ final Path tempDirectory = Files.createTempDirectory(getClass().getCanonicalName());
+ try {
+ Assertions.assertTrue(PathUtils.isEmpty(tempDirectory));
+ } finally {
+ Files.delete(tempDirectory);
+ }
+ Assertions.assertFalse(PathUtils.isEmpty(DIR_SIZE_1));
+ }
+
+ @Test
+ public void testisEmptyDirectory() throws IOException {
+ final Path tempDirectory = Files.createTempDirectory(getClass().getCanonicalName());
+ try {
+ Assertions.assertTrue(PathUtils.isEmptyDirectory(tempDirectory));
+ } finally {
+ Files.delete(tempDirectory);
+ }
+ Assertions.assertFalse(PathUtils.isEmptyDirectory(DIR_SIZE_1));
+ }
+
+ @Test
+ public void testisEmptyFile() throws IOException {
+ Assertions.assertTrue(PathUtils.isEmptyFile(FILE_SIZE_0));
+ Assertions.assertFalse(PathUtils.isEmptyFile(FILE_SIZE_1));
+ }
+}

[IO-632] Add PathUtils for operations on NIO Path.