Skip to content

Commit 496f692

Browse files
committed
throw IOException in find command
This is to be consistent with other methods (ls, cat and others)
1 parent 987c59d commit 496f692

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/main/java/io/github/benas/unixstream/UnixStream.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,17 @@ static UnixStream<String> pwd() {
136136
* Find files by name (recursively) in a given directory.
137137
*
138138
* @param directory the root directory
139-
* @param pattern the file name pattern with <a href="https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob">glob syntax</a>.
139+
* @param pattern the file name pattern with <a href="https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob">glob syntax</a>.
140140
* @return a new UnixStream with found files
141+
* @throws IOException thrown if an error occurs during reading the file
141142
*/
142-
static UnixStream<Path> find(final Path directory, final String pattern) {
143+
static UnixStream<Path> find(final Path directory, final String pattern) throws IOException {
143144
Objects.requireNonNull(directory, "The root directory must not be null");
144145
Objects.requireNonNull(pattern, "The file pattern must not be null");
145146
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
146-
try {
147-
return new UnixStreamImpl<>(walk(directory)
148-
.filter(path -> !isDirectory(path))
149-
.filter(path -> pathMatcher.matches(path.getFileName())));
150-
151-
} catch (IOException e) {
152-
throw new RuntimeException("Unable to find files in directory " + directory);
153-
}
147+
return new UnixStreamImpl<>(walk(directory)
148+
.filter(path -> !isDirectory(path))
149+
.filter(path -> pathMatcher.matches(path.getFileName())));
154150
}
155151

156152
/**

0 commit comments

Comments
 (0)