I'm busy creating a program that uses external programs. My problem is that the following code isn't efficient because it's filling my RAM and the main program is using to much cpu.

The bufferedReader reads the progress of a program mkvextract, the problem is that it outputs the same line for a long time, and the BufferedReader readline methode reads the same line over and over again.

Does anybody know a good alternative to this problem?

Java Code:
Runtime runtime = Runtime.getRuntime();          
Process p = runtime.exec(extractAllTracksCommand);

BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();

while (line != null) {

    if (line.contains("%")) {
        int beginIndex = line.indexOf(": ") + 2;
        int endIndex = line.indexOf("%");
        int progress = Integer.parseInt(line.substring(beginIndex, endIndex));
        line = reader.readLine();