Add a factory method and move test class to proper package.
MODIFY
src/main/java/org/apache/commons/io/file/PathUtils.java
src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -677,6 +677,18 @@ public static boolean isNewer(final Path file, final long timeMillis, final Link
return Files.getLastModifiedTime(file, options).toMillis() > timeMillis;
}
+ /**
+ * Creates a new DirectoryStream for Paths rooted at the given directory.
+ *
+ * @param dir the path to the directory to stream.
+ * @param pathFilter the directory stream filter.
+ * @return a new instance.
+ * @throws IOException if an I/O error occurs.
+ */
+ public static DirectoryStream<Path> newDirectoryStream(final Path dir, PathFilter pathFilter) throws IOException {
+ return Files.newDirectoryStream(dir, new DirectoryStreamFilter(pathFilter));
+ }
+
/**
* Returns true if the given options contain {@link StandardDeleteOption#OVERRIDE_READ_ONLY}.
*

RENAME
src/test/java/org/apache/commons/io/DirectoryStreamFilterTest.java
src/test/java/org/apache/commons/io/file/DirectoryStreamFilterTest.java
* limitations under the License.
*/
-package org.apache.commons.io;
+package org.apache.commons.io.file;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import org.apache.commons.io.file.DirectoryStreamFilter;
import org.apache.commons.io.file.PathFilter;
+import org.apache.commons.io.file.PathUtils;
import org.apache.commons.io.filefilter.NameFileFilter;
import org.junit.jupiter.api.Test;
@@ -63,4 +64,5 @@ public void testFilterByNameNot() throws Exception {
}
}
}
+
}

MODIFY
src/test/java/org/apache/commons/io/file/PathUtilsTest.java
src/test/java/org/apache/commons/io/file/PathUtilsTest.java
package org.apache.commons.io.file;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
+import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Iterator;
+import org.apache.commons.io.filefilter.NameFileFilter;
import org.junit.jupiter.api.Test;
public class PathUtilsTest extends TestArguments {
+ private static final String PATH_FIXTURE = "NOTICE.txt";
+
@Test
public void testCopyFile() throws IOException {
final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
try {
- final Path sourceFile = Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/file-size-1.bin");
- final Path targetFile = PathUtils.copyFileToDirectory(
- sourceFile, tempDir);
+ final Path sourceFile = Paths
+ .get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/file-size-1.bin");
+ final Path targetFile = PathUtils.copyFileToDirectory(sourceFile, tempDir);
assertTrue(Files.exists(targetFile));
assertEquals(Files.size(sourceFile), Files.size(targetFile));
} finally {
@@ -43,4 +49,15 @@ public void testCopyFile() throws IOException {
}
}
+ @Test
+ public void testNewDirectoryStream() throws Exception {
+ final PathFilter pathFilter = new NameFileFilter(PATH_FIXTURE);
+ try (final DirectoryStream<Path> stream = PathUtils.newDirectoryStream(Paths.get("."), pathFilter)) {
+ final Iterator<Path> iterator = stream.iterator();
+ final Path path = iterator.next();
+ assertEquals(PATH_FIXTURE, path.getFileName().toString());
+ assertFalse(iterator.hasNext());
+ }
+ }
+
}

Add a factory method and move test class to proper package.