Skip to content

Commit a6774db

Browse files
committed
Add FilesUncheck.find(Path, int, BiPredicate<Path, BasicFileAttributes>,
FileVisitOption...)
1 parent fcb1ce5 commit a6774db

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ The <action> type attribute can be add,update,fix,remove.
5858
<action dev="ggregory" type="add" due-to="Gary Gregory">
5959
Add IOUtils.skip[Fully](InputStream, long, Supplier&lt;byte[]&gt;).
6060
</action>
61+
<action dev="ggregory" type="add" due-to="Gary Gregory">
62+
Add FilesUncheck.find(Path, int, BiPredicate%lt;Path, BasicFileAttributes&gt;, FileVisitOption...)
63+
</action>
6164
<!-- FIX -->
6265
<action dev="ggregory" type="fix" issue="IO-799" due-to="Jeroen van der Vegt, Gary Gregory">
6366
ReaderInputStream.read() throws an exception instead of returning -1 when called again after returning -1.

src/main/java/org/apache/commons/io/file/FilesUncheck.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.List;
4343
import java.util.Map;
4444
import java.util.Set;
45+
import java.util.function.BiPredicate;
4546
import java.util.stream.Stream;
4647

4748
import org.apache.commons.io.function.Uncheck;
@@ -241,6 +242,22 @@ public static boolean deleteIfExists(final Path path) {
241242
return Uncheck.apply(Files::deleteIfExists, path);
242243
}
243244

245+
/**
246+
* Delegates to {@link Files#find(Path, int, BiPredicate, FileVisitOption...)} throwing {@link UncheckedIOException} instead of {@link IOException}.
247+
*
248+
* @param start See delegate.
249+
* @param maxDepth See delegate.
250+
* @param matcher See delegate.
251+
* @param options See delegate.
252+
* @return See delegate.
253+
* @throws UncheckedIOException Wraps an {@link IOException}.
254+
* @since 2.14.0
255+
*/
256+
public static Stream<Path> find(final Path start, final int maxDepth, final BiPredicate<Path, BasicFileAttributes> matcher,
257+
final FileVisitOption... options) {
258+
return Uncheck.apply(Files::find, start, maxDepth, matcher, options);
259+
}
260+
244261
/**
245262
* Delegates to {@link Files#getAttribute(Path, String, LinkOption...)} throwing {@link UncheckedIOException} instead of
246263
* {@link IOException}.

src/test/java/org/apache/commons/io/file/FilesUncheckTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ public void testDeleteIfExists() {
164164
assertFalse(FilesUncheck.deleteIfExists(NEW_FILE_PATH));
165165
}
166166

167+
@Test
168+
public void testFind() {
169+
assertNotNull(FilesUncheck.find(FILE_PATH_EMPTY, 0, (t, u) -> false));
170+
}
171+
167172
@Test
168173
public void testGetAttribute() {
169174
assertEquals(0L, FilesUncheck.getAttribute(FILE_PATH_EMPTY, "basic:size", LinkOption.NOFOLLOW_LINKS));

0 commit comments

Comments
 (0)