Polish "Use try-with-resources to close resources automatically"

- Apply code formatting
- Use try-with-resources in many other places that were missed in the
  pull request

Closes gh-8045
This commit is contained in:
Andy Wilkinson
2017-05-23 17:24:01 +01:00
parent 3e797c326a
commit d5438c299c
78 changed files with 284 additions and 703 deletions

View File

@@ -365,18 +365,14 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
private byte[] createFakeZipArchive(String fileName, String content)
throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(bos);
try {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(bos)) {
ZipEntry entry = new ZipEntry(fileName);
zos.putNextEntry(entry);
zos.write(content.getBytes());
zos.closeEntry();
return bos.toByteArray();
}
finally {
bos.close();
}
return bos.toByteArray();
}
private static class TestableInitCommandOptionHandler

View File

@@ -92,14 +92,10 @@ public class InitializrServiceMetadataTests {
private static JSONObject readJson(String version) throws IOException, JSONException {
Resource resource = new ClassPathResource(
"metadata/service-metadata-" + version + ".json");
InputStream stream = resource.getInputStream();
try {
try (InputStream stream = resource.getInputStream()) {
return new JSONObject(
StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
}
finally {
stream.close();
}
}
}