From 22b722b26e96b45b83f4bd617b06cecdd53990f0 Mon Sep 17 00:00:00 2001 From: Kyle Thomson Date: Tue, 4 Dec 2018 12:04:59 -0800 Subject: [PATCH] fix: Making hello world java sample more idiomatic (#802) --- .../src/main/java/helloworld/App.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/samcli/local/init/templates/cookiecutter-aws-sam-hello-java/{{cookiecutter.project_name}}/src/main/java/helloworld/App.java b/samcli/local/init/templates/cookiecutter-aws-sam-hello-java/{{cookiecutter.project_name}}/src/main/java/helloworld/App.java index fdbf4f188b..18890033e1 100644 --- a/samcli/local/init/templates/cookiecutter-aws-sam-hello-java/{{cookiecutter.project_name}}/src/main/java/helloworld/App.java +++ b/samcli/local/init/templates/cookiecutter-aws-sam-hello-java/{{cookiecutter.project_name}}/src/main/java/helloworld/App.java @@ -6,7 +6,7 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; -import java.util.StringJoiner; +import java.util.stream.Collectors; import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestHandler; @@ -30,20 +30,9 @@ public Object handleRequest(final Object input, final Context context) { } private String getPageContents(String address) throws IOException{ - BufferedReader br = null; - StringJoiner lines = new StringJoiner(System.lineSeparator()); - try { - URL url = new URL(address); - br = new BufferedReader(new InputStreamReader(url.openStream())); - String line; - while ((line = br.readLine()) != null) { - lines.add(line); - } - } finally { - if (br != null) { - br.close(); - } + URL url = new URL(address); + try(BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) { + return br.lines().collect(Collectors.joining(System.lineSeparator())); } - return lines.toString(); } }