Skip to content

Commit

Permalink
moved try-with-resource to the parent try statement
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollovati committed Feb 15, 2022
1 parent 7144e28 commit e33b426
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,17 @@ private int measureLogEntryTimeDistance(String startFragment,
Pattern endPattern = createPattern(endFragment);
AtomicInteger startTime = new AtomicInteger();
AtomicInteger endTime = new AtomicInteger();
try {
try (Stream<String> lines = Files.lines(getLogPath())) {
lines.forEach(line -> {
Matcher matcherFirst = startPattern.matcher(line);
if (matcherFirst.matches() && startTime.get() == 0) {
startTime.set(Integer.parseInt(matcherFirst.group(1)));
}
Matcher matcherEnd = endPattern.matcher(line);
if (matcherEnd.matches()) {
endTime.set(Integer.parseInt(matcherEnd.group(1)));
}
});
}
try (Stream<String> lines = Files.lines(getLogPath())) {
lines.forEach(line -> {
Matcher matcherFirst = startPattern.matcher(line);
if (matcherFirst.matches() && startTime.get() == 0) {
startTime.set(Integer.parseInt(matcherFirst.group(1)));
}
Matcher matcherEnd = endPattern.matcher(line);
if (matcherEnd.matches()) {
endTime.set(Integer.parseInt(matcherEnd.group(1)));
}
});
if (startTime.get() == 0 && failIfNotFound) {
throw new RuntimeException("No match: " + startFragment);
}
Expand Down

0 comments on commit e33b426

Please sign in to comment.