svn commit: r832481 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java xdocs/changes.xml

1 message Options
Embed this post
Permalink
rgoers

svn commit: r832481 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java xdocs/changes.xml

Reply Threaded More More options
Print post
Permalink
Author: rgoers
Date: Tue Nov  3 17:36:07 2009
New Revision: 832481

URL: http://svn.apache.org/viewvc?rev=832481&view=rev
Log:
Apply patch for VFS-289 provided by Kirill Safonov

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java
    commons/proper/vfs/trunk/xdocs/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java?rev=832481&r1=832480&r2=832481&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java Tue Nov  3 17:36:07 2009
@@ -585,13 +585,19 @@
     protected InputStream doGetInputStream() throws Exception
     {
         final FtpClient client = ftpFs.getClient();
-        final InputStream instr = client.retrieveFileStream(relPath);
-        // VFS-210
-        if (instr == null)
-        {
-            throw new FileNotFoundException(getName().toString());
+        try {
+            final InputStream instr = client.retrieveFileStream(relPath);
+            // VFS-210
+            if (instr == null)
+            {
+                throw new FileNotFoundException(getName().toString());
+            }
+            return new FtpInputStream(client, instr);
+        }
+        catch (Exception e) {
+            ftpFs.putClient(client);
+            throw e;
         }
-        return new FtpInputStream(client, instr);
     }
 
     protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception
@@ -606,26 +612,32 @@
         throws Exception
     {
         final FtpClient client = ftpFs.getClient();
-        OutputStream out = null;
-        if (bAppend)
-        {
-            out = client.appendFileStream(relPath);
-        }
-        else
-        {
-            out = client.storeFileStream(relPath);
-        }
+        try {
+            OutputStream out = null;
+            if (bAppend)
+            {
+                out = client.appendFileStream(relPath);
+            }
+            else
+            {
+                out = client.storeFileStream(relPath);
+            }
 
-        if (out == null)
-        {
-            throw new FileSystemException("vfs.provider.ftp/output-error.debug", new Object[]
-                {
-                    this.getName(),
-                    client.getReplyString()
-                });
-        }
+            if (out == null)
+            {
+                throw new FileSystemException("vfs.provider.ftp/output-error.debug", new Object[]
+                    {
+                        this.getName(),
+                        client.getReplyString()
+                    });
+            }
 
-        return new FtpOutputStream(client, out);
+            return new FtpOutputStream(client, out);
+        }
+        catch (Exception e) {
+            ftpFs.putClient(client);
+            throw e;
+        }
     }
 
     String getRelPath()
@@ -636,16 +648,22 @@
     FtpInputStream getInputStream(long filePointer) throws IOException
     {
         final FtpClient client = ftpFs.getClient();
-        final InputStream instr = client.retrieveFileStream(relPath, filePointer);
-        if (instr == null)
-        {
-            throw new FileSystemException("vfs.provider.ftp/input-error.debug", new Object[]
-                {
-                    this.getName(),
-                    client.getReplyString()
-                });
+        try {
+            final InputStream instr = client.retrieveFileStream(relPath, filePointer);
+            if (instr == null)
+            {
+                throw new FileSystemException("vfs.provider.ftp/input-error.debug", new Object[]
+                    {
+                        this.getName(),
+                        client.getReplyString()
+                    });
+            }
+            return new FtpInputStream(client, instr);
+        }
+        catch (IOException e) {
+            ftpFs.putClient(client);
+            throw e;
         }
-        return new FtpInputStream(client, instr);
     }
 
     /**

Modified: commons/proper/vfs/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/xdocs/changes.xml?rev=832481&r1=832480&r2=832481&view=diff
==============================================================================
--- commons/proper/vfs/trunk/xdocs/changes.xml (original)
+++ commons/proper/vfs/trunk/xdocs/changes.xml Tue Nov  3 17:36:07 2009
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0" date="in SVN" description="">
+      <action dev="rgoers" type="fix" issue="VFS-289" due-to="Kirill Safonov">
+        FTP connection is not released If exception is thrown out of FtpFileObject.doGetOutputStream().
+      </action>
       <action dev="rgoers" type="fix" issue="VFS-286" due-to="Kirill Safonov">
         SftpFileObject.doListChildrenResolved() changes the working dir before doing ChannelSftp.ls() call.
         If ls() throws an exception, the current directory is not reset. All the subsequent operations that rely on the