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:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user