svn commit: r505776 - in /jakarta/slide/trunk: WHATSNEW webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java

[email protected]
Newsgroups gmane.comp.jakarta.slide.devel
Message-ID <[email protected]>
Author: antoine
Date: Sat Feb 10 13:59:00 2007
New Revision: 505776

URL: http://svn.apache.org/viewvc?view=rev&rev=505776
Log:
closing streams properly in getMethod(String path, File file), Bugzilla 41574

Modified:
    jakarta/slide/trunk/WHATSNEW
    jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java

Modified: jakarta/slide/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/WHATSNEW?view=diff&rev=505776&r1=505775&r2=505776
==============================================================================
--- jakarta/slide/trunk/WHATSNEW (original)
+++ jakarta/slide/trunk/WHATSNEW Sat Feb 10 13:59:00 2007
@@ -1,4 +1,4 @@
-Changes from slide 2.1 to current SVN version
+	Changes from slide 2.1 to current SVN version
 =============================================
 
 Changes that could break older environments:
@@ -11,6 +11,9 @@
 
 * Unclosed FileInputStream in WebdavResource.putMethod
   Bugzilla 40835.
+
+* Potentially unclosed InputStream and FileOutputStream in WebdavResource.getMethod(String path, File file)
+  Bugzilla 41574. 
 
 Other changes:
 --------------

Modified: jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java?view=diff&rev=505776&r1=505775&r2=505776
==============================================================================
--- jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java (original)
+++ jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java Sat Feb 10 13:59:00 2007
@@ -2229,8 +2229,6 @@
      * Set the URL encoding flag for this http URL.
      *
      * @param encodeURLs true if it is encoded.
-     * @exception MalformedURLException
-     * @exception IOException
      *
      * @deprecated  No longer has any effect.
      */
@@ -2625,20 +2623,28 @@
         // get the file only if status is any kind of OK
         if (statusCode >= 200 && statusCode < 300) {
 
-            // Do a simple little loop to read the response back into the passed
-            // file parameter.
-            InputStream inStream = method.getResponseBodyAsStream();
-
-            FileOutputStream fos = new FileOutputStream(file);
-            byte buffer[] = new byte[65535];
-            int bytesRead;
-            while ((bytesRead = inStream.read(buffer)) >= 0) {
-                fos.write(buffer, 0, bytesRead);
-            }
-            inStream.close();
-            fos.close();
+            FileOutputStream fos = null;
+            InputStream inStream = null;
+            try {
+                // Do a simple little loop to read the response back into the passed
+                // file parameter.
+                inStream = method.getResponseBodyAsStream();
+
+                fos = new FileOutputStream(file);
+                byte buffer[] = new byte[65535];
+                int bytesRead;
+                while ((bytesRead = inStream.read(buffer)) >= 0) {
+                    fos.write(buffer, 0, bytesRead);
+                }
 
-            return true;
+                return true;
+
+            } finally {
+                if(fos != null)
+                    fos.close();
+                if(inStream != null)
+                    inStream.close();
+            }
 
         } else {
             return false;
@@ -4259,7 +4265,7 @@
      * @param path the server relative path of the resource to lock
      * @param owner The owner string.
      * @param timeout the timeout value.
-     * @param locktype, the scope of lock.
+     * @param lockType, the scope of lock.
      * @return true if the method is succeeded.
      * @exception HttpException
      * @exception IOException
@@ -4278,7 +4284,7 @@
      * @param path the server relative path of the resource to lock
      * @param owner The owner string.
      * @param timeout the timeout value.
-     * @param locktype, the scope of lock.
+     * @param lockType, the scope of lock.
      * @return true if the method is succeeded.
      * @exception HttpException
      * @exception IOException
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.