Skip to content

Commit 28b063d

Browse files
committed
use Path instead of String for files
1 parent e507419 commit 28b063d

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
@@ -113,8 +113,8 @@ static <T> UnixStream<T> from(final Stream<T> stream) {
113113
* @return an UnixStream with file names of the current directory.
114114
* @throws IOException thrown if an error occurs during reading the current directory
115115
*/
116-
static UnixStream<String> ls() throws IOException {
117-
return ls(Paths.get("").toFile().getAbsolutePath());
116+
static UnixStream<Path> ls() throws IOException {
117+
return ls(Paths.get(""));
118118
}
119119

120120
/**
@@ -124,22 +124,18 @@ static UnixStream<String> ls() throws IOException {
124124
* @return an UnixStream with file names of the given directory.
125125
* @throws IOException thrown if an error occurs during reading the directory
126126
*/
127-
static UnixStream<String> ls(final String directory) throws IOException {
127+
static UnixStream<Path> ls(final Path directory) throws IOException {
128128
Objects.requireNonNull(directory, "The directory must not be null");
129-
File[] files = new File(directory).listFiles();
130-
if (files != null) {
131-
return new UnixStreamImpl<>(Arrays.stream(files).map(File::getName));
132-
}
133-
return new UnixStreamImpl<>(Stream.empty());
129+
return new UnixStreamImpl<>(Files.list(directory));
134130
}
135131

136132
/**
137133
* Create a new UnixStream with the absolute path of the current directory.
138134
*
139135
* @return a new UnixStream with the absolute path of the current directory.
140136
*/
141-
static UnixStream<String> pwd() {
142-
return new UnixStreamImpl<>(Stream.of(Paths.get("").toFile().getAbsolutePath()));
137+
static UnixStream<Path> pwd() {
138+
return new UnixStreamImpl<>(Stream.of(Paths.get("")));
143139
}
144140

145141

0 commit comments

Comments
 (0)