Merge pull request #11436 from izeye:buffered-reader-lines

* pr/11436:
  Use BufferedReader.lines()
pull/11432/merge
Stephane Nicoll 7 years ago
commit 9c1acb5f46

@ -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 {

@ -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();
}

@ -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);

@ -17,7 +17,6 @@
package org.springframework.boot.test.context.assertj;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
@ -410,17 +409,11 @@ public class ApplicationContextAssert<C extends ApplicationContext>
BufferedReader reader = new BufferedReader(new StringReader(input));
StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer);
try {
String line;
while ((line = reader.readLine()) != null) {
printer.print(" ");
printer.println(line);
}
return writer.toString();
}
catch (IOException ex) {
return input;
}
reader.lines().forEach((line) -> {
printer.print(" ");
printer.println(line);
});
return writer.toString();
}
}

@ -147,17 +147,13 @@ public class RunProcess {
}
private void redirectOutput(Process process) {
final BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
new Thread(() -> {
try {
String line = reader.readLine();
while (line != null) {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()))) {
reader.lines().forEach((line) -> {
System.out.println(line);
line = reader.readLine();
System.out.flush();
}
reader.close();
});
}
catch (Exception ex) {
// Ignore

@ -19,8 +19,8 @@ package org.springframework.boot.diagnostics.analyzer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
@ -125,14 +125,9 @@ public class BeanCurrentlyInCreationFailureAnalyzerTests {
private List<String> readDescriptionLines(FailureAnalysis analysis)
throws IOException {
try (BufferedReader lineReader = new BufferedReader(
try (BufferedReader reader = new BufferedReader(
new StringReader(analysis.getDescription()))) {
List<String> lines = new ArrayList<>();
String line;
while ((line = lineReader.readLine()) != null) {
lines.add(line);
}
return lines;
return reader.lines().collect(Collectors.toList());
}
}

Loading…
Cancel
Save