Skip to content

Commit

Permalink
Merge pull request #247 from espaillato/patch-1
Browse files Browse the repository at this point in the history
Update BinLog.java - fixes FD leak
  • Loading branch information
ar authored Jun 17, 2022
2 parents 7f3c5ae + 9d6a85c commit 6449f59
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions modules/binlog/src/main/java/org/jpos/binlog/BinLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ protected String getLastClosed (Path dir) throws IOException {
}

protected String getFirst(Path dir) throws IOException {
return StreamSupport.stream(Files.newDirectoryStream(dir, filePattern).spliterator(), false)
.map(Objects::toString).sorted(String::compareTo).findFirst().orElse(null);
try (DirectoryStream<Path> files = Files.newDirectoryStream(dir, filePattern)) {
return StreamSupport.stream(files.spliterator(), false)
.map(Objects::toString).sorted(String::compareTo).findFirst().orElse(null);
}
}

private void verifyHeader(Path file, AsynchronousFileChannel raf) throws IOException {
Expand Down Expand Up @@ -331,16 +333,20 @@ private void lock (long timeout) throws IOException, InterruptedException {
}

private List<String> getFiles(Path dir) throws IOException {
return StreamSupport.stream(Files.newDirectoryStream(dir, filePattern).spliterator(), false)
.map(Objects::toString)
.sorted(String::compareTo)
.collect(Collectors.toList());
try (DirectoryStream<Path> files = Files.newDirectoryStream(dir, filePattern)) {
return StreamSupport.stream(files.spliterator(), false)
.map(Objects::toString)
.sorted(String::compareTo)
.collect(Collectors.toList());
}
}
private List<String> getFilesReversed(Path dir) throws IOException {
return StreamSupport.stream(Files.newDirectoryStream(dir, filePattern).spliterator(), false)
.map(Objects::toString)
.sorted((s1, s2) -> -s1.compareTo(s2))
.collect(Collectors.toList());
try (DirectoryStream<Path> files = Files.newDirectoryStream(dir, filePattern)) {
return StreamSupport.stream(files.spliterator(), false)
.map(Objects::toString)
.sorted((s1, s2) -> -s1.compareTo(s2))
.collect(Collectors.toList());
}
}

private boolean isClosed (Path f) throws IOException {
Expand Down Expand Up @@ -505,4 +511,4 @@ public byte[] get() {
return data;
}
}
}
}

0 comments on commit 6449f59

Please sign in to comment.