diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/DefaultDocumentLoader.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/DefaultDocumentLoader.java index 488e15c9..9b488f42 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/DefaultDocumentLoader.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/DefaultDocumentLoader.java @@ -93,9 +93,7 @@ public class DefaultDocumentLoader implements DocumentLoader { } public Document loadDocument(Resource resource) throws IOException, ParserConfigurationException, SAXException { - InputStream is = null; - try { - is = resource.getInputStream(); + try (InputStream is = resource.getInputStream()) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(isValidating()); factory.setNamespaceAware(true); @@ -111,10 +109,6 @@ public class DefaultDocumentLoader implements DocumentLoader { docBuilder.setErrorHandler(new SimpleSaxErrorHandler(logger)); docBuilder.setEntityResolver(getEntityResolver()); return docBuilder.parse(is); - } finally { - if (is != null) { - is.close(); - } } } } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/SerializedFlowExecutionSnapshot.java b/spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/SerializedFlowExecutionSnapshot.java index 5d1b46e6..06b17281 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/SerializedFlowExecutionSnapshot.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/SerializedFlowExecutionSnapshot.java @@ -168,13 +168,10 @@ public class SerializedFlowExecutionSnapshot extends FlowExecutionSnapshot imple */ protected byte[] serialize(FlowExecution flowExecution) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - ObjectOutputStream oos = new ObjectOutputStream(baos); - try { + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(flowExecution); oos.flush(); return baos.toByteArray(); - } finally { - oos.close(); } } @@ -189,11 +186,8 @@ public class SerializedFlowExecutionSnapshot extends FlowExecutionSnapshot imple */ protected FlowExecution deserialize(byte[] data, ClassLoader classLoader) throws IOException, ClassNotFoundException { - ObjectInputStream ois = new ConfigurableObjectInputStream(new ByteArrayInputStream(data), classLoader); - try { + try (ObjectInputStream ois = new ConfigurableObjectInputStream(new ByteArrayInputStream(data), classLoader)) { return (FlowExecution) ois.readObject(); - } finally { - ois.close(); } } @@ -203,12 +197,9 @@ public class SerializedFlowExecutionSnapshot extends FlowExecutionSnapshot imple */ protected byte[] compress(byte[] dataToCompress) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gzipos = new GZIPOutputStream(baos); - try { + try (GZIPOutputStream gzipos = new GZIPOutputStream(baos)) { gzipos.write(dataToCompress); gzipos.flush(); - } finally { - gzipos.close(); } return baos.toByteArray(); }