Skip to content

Commit

Permalink
fix: Making hello world java sample more idiomatic (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiiadi authored and jfuss committed Dec 4, 2018
1 parent 47106dd commit 22b722b
Showing 1 changed file with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}

0 comments on commit 22b722b

Please sign in to comment.