felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From walk...@apache.org
Subject svn commit: r561742 - /felix/trunk/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java
Date Wed, 01 Aug 2007 09:36:39 GMT
Author: walkerr
Date: Wed Aug  1 02:36:38 2007
New Revision: 561742

URL: http://svn.apache.org/viewvc?view=rev&rev=561742
Log:
Ensure URL stream is closed once bytes have been read and copied to response (FELIX-330).

Modified:
    felix/trunk/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java

Modified: felix/trunk/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java?view=diff&rev=561742&r1=561741&r2=561742
==============================================================================
--- felix/trunk/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java
(original)
+++ felix/trunk/http.jetty/src/main/java/org/apache/felix/http/jetty/OsgiResourceHandler.java
Wed Aug  1 02:36:38 2007
@@ -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 
-        {
-            response.setContentLength(len);
-        } 
-        catch (IllegalStateException ex) 
+        try
         {
-            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();
+        }        
     }
 }



Mime
View raw message