Skip to content

Commit

Permalink
Merge pull request #62 from jfdenise/master
Browse files Browse the repository at this point in the history
Fix for AESH-455, grep close file
  • Loading branch information
stalep committed Feb 20, 2018
2 parents 9b7b09e + 37a4766 commit 0c19ef8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions aesh/src/main/java/org/aesh/extensions/grep/Grep.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -45,7 +46,7 @@
@CommandDefinition(name = "grep",
description = "[OPTION]... PATTERN [FILE]...\n"+
"Search for PATTERN in each FILE or standard input.\n"+
"PATTERN is, by default, a basic regular expression (BRE).\n" +
"PATTERN is a regular expression.\n" +
"Example: grep -i 'hello world' menu.h main.c\n")
public class Grep implements Command<CommandInvocation> {

Expand Down Expand Up @@ -145,12 +146,12 @@ private void doGrep(Resource file, CommandInvocation invocation) throws IOExcept
if (!file.exists()) {
invocation.println("grep: " + file.toString() + ": No such file or directory");
} else if (file.isLeaf()) {
BufferedReader br = new BufferedReader(new InputStreamReader(file.read()));
List<String> inputLines = new ArrayList<>();

String line;
while ((line = br.readLine()) != null) {
inputLines.add(line);
try (BufferedReader reader = Files.newBufferedReader(Paths.get(file.getAbsolutePath()))) {
String line;
while ((line = reader.readLine()) != null) {
inputLines.add(line);
}
}
doGrep(inputLines, invocation);
}
Expand Down

0 comments on commit 0c19ef8

Please sign in to comment.