Browse Source

Merge pull request #1671 from igor-suhorukov:master

* pr/1671:
  Change this "try" to a try-with-resources
pull/1671/merge
Stephane Nicoll 7 years ago
parent
commit
0d757bf3f7
  1. 6
      spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java
  2. 6
      spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java
  3. 8
      spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java
  4. 13
      spring-web/src/main/java/org/springframework/http/MediaTypeFactory.java
  5. 19
      spring-web/src/main/java/org/springframework/remoting/caucho/HessianExporter.java

6
spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java

@ -249,8 +249,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader @@ -249,8 +249,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
Properties props = new Properties();
try {
InputStream is = encodedResource.getResource().getInputStream();
try {
try (InputStream is = encodedResource.getResource().getInputStream()) {
if (encodedResource.getEncoding() != null) {
getPropertiesPersister().load(props, new InputStreamReader(is, encodedResource.getEncoding()));
}
@ -258,9 +257,6 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader @@ -258,9 +257,6 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
getPropertiesPersister().load(props, is);
}
}
finally {
is.close();
}
return registerBeanDefinitions(props, prefix, encodedResource.getResource().getDescription());
}
catch (IOException ex) {

6
spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java

@ -461,9 +461,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased @@ -461,9 +461,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
* @throws IOException if properties loading failed
*/
protected Properties loadProperties(Resource resource, String filename) throws IOException {
InputStream is = resource.getInputStream();
Properties props = newProperties();
try {
try (InputStream is = resource.getInputStream()) {
String resourceFilename = resource.getFilename();
if (resourceFilename != null && resourceFilename.endsWith(XML_SUFFIX)) {
if (logger.isDebugEnabled()) {
@ -494,9 +493,6 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased @@ -494,9 +493,6 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
}
return props;
}
finally {
is.close();
}
}
/**

8
spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java

@ -26,7 +26,6 @@ import java.security.AccessController; @@ -26,7 +26,6 @@ import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
@ -370,11 +369,8 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou @@ -370,11 +369,8 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
if (encoding == null) {
encoding = "ISO-8859-1";
}
try {
return loadBundle(new InputStreamReader(stream, encoding));
}
finally {
stream.close();
try (InputStreamReader bundleReader = new InputStreamReader(stream, encoding)) {
return loadBundle(bundleReader);
}
}
else {

13
spring-web/src/main/java/org/springframework/http/MediaTypeFactory.java

@ -60,9 +60,7 @@ public class MediaTypeFactory { @@ -60,9 +60,7 @@ public class MediaTypeFactory {
* @return a multi-value map, mapping media types to file extensions.
*/
private static MultiValueMap<String, MediaType> parseMimeTypes() {
InputStream is = null;
try {
is = MediaTypeFactory.class.getResourceAsStream(MIME_TYPES_FILE_NAME);
try (InputStream is = MediaTypeFactory.class.getResourceAsStream(MIME_TYPES_FILE_NAME)) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.US_ASCII));
MultiValueMap<String, MediaType> result = new LinkedMultiValueMap<>();
String line;
@ -82,15 +80,6 @@ public class MediaTypeFactory { @@ -82,15 +80,6 @@ public class MediaTypeFactory {
catch (IOException ex) {
throw new IllegalStateException("Could not load '" + MIME_TYPES_FILE_NAME + "'", ex);
}
finally {
if (is != null) {
try {
is.close();
}
catch (IOException ignore) {
}
}
}
}
/**

19
spring-web/src/main/java/org/springframework/remoting/caucho/HessianExporter.java

@ -158,15 +158,16 @@ public class HessianExporter extends RemoteExporter implements InitializingBean @@ -158,15 +158,16 @@ public class HessianExporter extends RemoteExporter implements InitializingBean
OutputStream osToUse = outputStream;
if (this.debugLogger != null && this.debugLogger.isDebugEnabled()) {
PrintWriter debugWriter = new PrintWriter(new CommonsLogWriter(this.debugLogger));
@SuppressWarnings("resource")
HessianDebugInputStream dis = new HessianDebugInputStream(inputStream, debugWriter);
@SuppressWarnings("resource")
HessianDebugOutputStream dos = new HessianDebugOutputStream(outputStream, debugWriter);
dis.startTop2();
dos.startTop2();
isToUse = dis;
osToUse = dos;
try (PrintWriter debugWriter = new PrintWriter(new CommonsLogWriter(this.debugLogger))){
@SuppressWarnings("resource")
HessianDebugInputStream dis = new HessianDebugInputStream(inputStream, debugWriter);
@SuppressWarnings("resource")
HessianDebugOutputStream dos = new HessianDebugOutputStream(outputStream, debugWriter);
dis.startTop2();
dos.startTop2();
isToUse = dis;
osToUse = dos;
}
}
if (!isToUse.markSupported()) {

Loading…
Cancel
Save