8038431: Close InputStream when finished retrieving XML Signature HTTP References
authormullan
Tue, 08 Apr 2014 11:57:57 -0400
changeset 23729 9567adf703ec
parent 23725 0190e5c0e70c
child 23730 c35edcf0144e
8038431: Close InputStream when finished retrieving XML Signature HTTP References Reviewed-by: xuelei
jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/resolver/implementations/ResolverDirectHTTP.java
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/resolver/implementations/ResolverDirectHTTP.java	Mon Apr 07 15:40:05 2014 +0100
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/resolver/implementations/ResolverDirectHTTP.java	Tue Apr 08 11:57:57 2014 -0400
@@ -108,6 +108,7 @@
     @Override
     public XMLSignatureInput engineResolveURI(ResourceResolverContext context)
         throws ResourceResolverException {
+        InputStream inputStream = null;
         try {
 
             // calculate new URI
@@ -139,7 +140,7 @@
             }
 
             String mimeType = urlConnection.getHeaderField("Content-Type");
-            InputStream inputStream = urlConnection.getInputStream();
+            inputStream = urlConnection.getInputStream();
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             byte buf[] = new byte[4096];
             int read = 0;
@@ -168,6 +169,16 @@
             throw new ResourceResolverException("generic.EmptyMessage", ex, context.attr, context.baseUri);
         } catch (IllegalArgumentException e) {
             throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri);
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    if (log.isLoggable(java.util.logging.Level.FINE)) {
+                        log.log(java.util.logging.Level.FINE, e.getMessage(), e);
+                    }
+                }
+            }
         }
     }