mirror of https://github.com/apache/ant-ivy
Use try with resources
This commit is contained in:
parent
b5b177b84d
commit
93f11da846
|
|
@ -341,31 +341,13 @@ public class IvyReport extends IvyTask {
|
|||
}
|
||||
}
|
||||
|
||||
InputStream inStream = null;
|
||||
OutputStream outStream = null;
|
||||
try {
|
||||
inStream = new BufferedInputStream(new FileInputStream(reportFile));
|
||||
outStream = new BufferedOutputStream(new FileOutputStream(outFile));
|
||||
try (InputStream inStream = new BufferedInputStream(new FileInputStream(reportFile));
|
||||
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(outFile))) {
|
||||
StreamResult res = new StreamResult(outStream);
|
||||
Source src = new StreamSource(inStream, JAXPUtils.getSystemId(style));
|
||||
transformer.transform(src, res);
|
||||
} catch (TransformerException e) {
|
||||
throw new BuildException(e);
|
||||
} finally {
|
||||
if (inStream != null) {
|
||||
try {
|
||||
inStream.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (outStream != null) {
|
||||
try {
|
||||
outStream.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (TransformerConfigurationException e) {
|
||||
|
|
|
|||
|
|
@ -497,9 +497,7 @@ public class TestHelper {
|
|||
* after this method since the associated socket is released and some other process can now use it.
|
||||
*/
|
||||
public static int getMaybeAvailablePort() {
|
||||
ServerSocket s = null;
|
||||
try {
|
||||
s = new ServerSocket(0);
|
||||
try (ServerSocket s = new ServerSocket(0)) {
|
||||
s.setReuseAddress(true);
|
||||
int port = s.getLocalPort();
|
||||
try {
|
||||
|
|
@ -510,14 +508,6 @@ public class TestHelper {
|
|||
return port;
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
} finally {
|
||||
if (s != null) {
|
||||
try {
|
||||
s.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Not TCP/IP port available");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue