Ensure URL stream is closed once bytes have been read and copied to response (FELIX-330).

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@561742 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java b/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java
index 8c7a250..0e942a9 100644
--- a/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java
+++ b/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java
@@ -175,25 +175,37 @@
             throws
                     IOException
     {
-        OutputStream os = response.getOutputStream();
-        InputStream is = url.openStream();
-        int len = 0;
-        byte[] buf = new byte[1024];
-        int n = 0;
-
-        while ((n = is.read(buf, 0, buf.length)) >= 0)
-        {
-            os.write(buf, 0, n);
-            len += n;
-        }
+        OutputStream os = null;
+        InputStream is = null;
         
-        try 
+        try
         {
-            response.setContentLength(len);
-        } 
-        catch (IllegalStateException ex) 
-        {
-            System.err.println("OsgiResourceHandler: " + ex);
+            os = response.getOutputStream();
+            is = url.openStream();
+        
+            int len = 0;
+            byte[] buf = new byte[1024];
+            int n = 0;
+    
+            while ((n = is.read(buf, 0, buf.length)) >= 0)
+            {
+                os.write(buf, 0, n);
+                len += n;
+            }
+            
+            try 
+            {
+                response.setContentLength(len);
+            } 
+            catch (IllegalStateException ex) 
+            {
+                System.err.println("OsgiResourceHandler: " + ex);
+            }
         }
+        finally
+        {
+            if (is != null) is.close();
+            if (os != null) os.close();
+        }        
     }
 }