Use try with close
See gh-33987
This commit is contained in:
committed by
Phillip Webb
parent
0e68cae57f
commit
d3efd7e091
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -128,12 +128,9 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
|
||||
*/
|
||||
@Override
|
||||
public void writeEntry(String entryName, InputStream inputStream) throws IOException {
|
||||
try {
|
||||
try (inputStream) {
|
||||
writeEntry(entryName, new InputStreamEntryWriter(inputStream));
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -68,14 +68,11 @@ public class DefaultLaunchScript implements LaunchScript {
|
||||
}
|
||||
|
||||
private String loadContent(InputStream inputStream) throws IOException {
|
||||
try {
|
||||
try (inputStream) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
copy(inputStream, outputStream);
|
||||
return outputStream.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,12 +43,9 @@ final class SizeCalculatingEntryWriter implements EntryWriter {
|
||||
|
||||
private SizeCalculatingEntryWriter(EntryWriter entryWriter) throws IOException {
|
||||
SizeCalculatingOutputStream outputStream = new SizeCalculatingOutputStream();
|
||||
try {
|
||||
try (outputStream) {
|
||||
entryWriter.write(outputStream);
|
||||
}
|
||||
finally {
|
||||
outputStream.close();
|
||||
}
|
||||
this.content = outputStream.getContent();
|
||||
this.size = outputStream.getSize();
|
||||
}
|
||||
@@ -67,12 +64,9 @@ final class SizeCalculatingEntryWriter implements EntryWriter {
|
||||
}
|
||||
|
||||
private void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
|
||||
try {
|
||||
try (inputStream) {
|
||||
StreamUtils.copy(inputStream, outputStream);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user