Use try-with-resources instead of the old-style finally block
Change-Id: If0d7bd488b83c545915d50a1bf253f4d6c2eaca9
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serverconfig/ServerConfigServlet.java b/src/main/java/com/googlesource/gerrit/plugins/serverconfig/ServerConfigServlet.java
index 4d6324b..fd254cf 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serverconfig/ServerConfigServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serverconfig/ServerConfigServlet.java
@@ -146,12 +146,9 @@
res.setContentType("application/octet-stream");
res.setContentLength(message.length());
byte[] bytes = message.getBytes(Charsets.UTF_8);
- ByteArrayInputStream in = new ByteArrayInputStream(bytes);
OutputStream out = res.getOutputStream();
- try {
+ try (ByteArrayInputStream in = new ByteArrayInputStream(bytes)) {
ByteStreams.copy(in, out);
- } finally {
- in.close();
}
}
@@ -213,11 +210,8 @@
res.setContentType("application/octet-stream");
res.setContentLength((int) f.length());
OutputStream out = res.getOutputStream();
- InputStream in = new FileInputStream(f);
- try {
+ try (InputStream in = new FileInputStream(f)) {
ByteStreams.copy(in, out);
- } finally {
- in.close();
}
}
@@ -230,11 +224,8 @@
private void streamRequestToFile(HttpServletRequest req, File file)
throws IOException, FileNotFoundException {
InputStream in = req.getInputStream();
- OutputStream out = new FileOutputStream(file);
- try {
+ try (OutputStream out = new FileOutputStream(file)) {
ByteStreams.copy(in, out);
- } finally {
- out.close();
}
}
}