Skip to content

Commit

Permalink
change to try with resources
Browse files Browse the repository at this point in the history
  • Loading branch information
SAFELAYER\carles.guell committed Jan 23, 2019
1 parent 7783c03 commit efa961d
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions builtins/src/main/java/org/jline/builtins/Completers.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -302,25 +303,22 @@ public void complete(LineReader reader, ParsedLine commandLine, final List<Candi
curBuf = "";
current = getUserDir();
}
try {
Files.newDirectoryStream(current, this::accept).forEach(p -> {
String value = curBuf + p.getFileName().toString();
if (Files.isDirectory(p)) {
candidates.add(new Candidate(
value + (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH) ? sep : ""),
getDisplay(reader.getTerminal(), p),
null, null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? sep : null,
null,
false));
} else {
candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p),
null, null, null, null, true));
}
});
} catch (IOException e) {
// Ignore
}
try (DirectoryStream<Path> directory = Files.newDirectoryStream(current, this::accept)) {
directory.forEach(p -> {
String value = curBuf + p.getFileName().toString();
if (Files.isDirectory(p)) {
candidates.add(
new Candidate(value + (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH) ? sep : ""),
getDisplay(reader.getTerminal(), p), null, null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? sep : null, null, false));
} else {
candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p), null, null, null, null,
true));
}
});
} catch (IOException e) {
// Ignore
}
}

protected boolean accept(Path path) {
Expand Down

0 comments on commit efa961d

Please sign in to comment.