Use BufferedReader.lines()

Closes gh-11436
This commit is contained in:
Johnny Lim
2017-12-27 14:36:38 +09:00
committed by Stephane Nicoll
parent 50a4982a52
commit 8f7ab95e0e
6 changed files with 19 additions and 57 deletions

View File

@@ -28,6 +28,7 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -159,19 +160,9 @@ public final class CommandLineInvoker {
private List<String> getLines(StringBuffer buffer) {
BufferedReader reader = new BufferedReader(
new StringReader(buffer.toString()));
String line;
List<String> lines = new ArrayList<>();
try {
while ((line = reader.readLine()) != null) {
if (!line.startsWith("Picked up ")) {
lines.add(line);
}
}
}
catch (IOException ex) {
throw new RuntimeException("Failed to read output");
}
return lines;
return reader.lines()
.filter((line) -> !line.startsWith("Picked up "))
.collect(Collectors.toList());
}
public int await() throws InterruptedException {

View File

@@ -18,7 +18,6 @@ package org.springframework.boot.cli.compiler.maven;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
@@ -174,16 +173,8 @@ public class MavenSettings {
private String indentLines(String input, String indent) {
StringWriter indented = new StringWriter();
PrintWriter writer = new PrintWriter(indented);
String line;
BufferedReader reader = new BufferedReader(new StringReader(input));
try {
while ((line = reader.readLine()) != null) {
writer.println(indent + line);
}
}
catch (IOException ex) {
return input;
}
reader.lines().forEach((line) -> writer.println(indent + line));
return indented.toString();
}

View File

@@ -29,6 +29,7 @@ import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.junit.Assume;
import org.junit.rules.TestRule;
@@ -192,12 +193,7 @@ public class CliTester implements TestRule {
InputStream stream = URI.create("http://localhost:" + port + uri).toURL()
.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
StringBuilder result = new StringBuilder();
while ((line = reader.readLine()) != null) {
result.append(line);
}
return result.toString();
return reader.lines().collect(Collectors.joining());
}
catch (Exception ex) {
throw new IllegalStateException(ex);