Use try-with-resource in XmlBeanDefinitionReader
Closes gh-24492
This commit is contained in:
parent
96e77d417b
commit
97ba00eff2
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -327,19 +327,14 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
|
||||||
throw new BeanDefinitionStoreException(
|
throw new BeanDefinitionStoreException(
|
||||||
"Detected cyclic loading of " + encodedResource + " - check your import definitions!");
|
"Detected cyclic loading of " + encodedResource + " - check your import definitions!");
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
InputStream inputStream = encodedResource.getResource().getInputStream();
|
try (InputStream inputStream = encodedResource.getResource().getInputStream()) {
|
||||||
try {
|
|
||||||
InputSource inputSource = new InputSource(inputStream);
|
InputSource inputSource = new InputSource(inputStream);
|
||||||
if (encodedResource.getEncoding() != null) {
|
if (encodedResource.getEncoding() != null) {
|
||||||
inputSource.setEncoding(encodedResource.getEncoding());
|
inputSource.setEncoding(encodedResource.getEncoding());
|
||||||
}
|
}
|
||||||
return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
|
return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
throw new BeanDefinitionStoreException(
|
throw new BeanDefinitionStoreException(
|
||||||
"IOException parsing XML document from " + encodedResource.getResource(), ex);
|
"IOException parsing XML document from " + encodedResource.getResource(), ex);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue