commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1750872 - /commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
Date Fri, 01 Jul 2016 04:51:53 GMT
Author: ggregory
Date: Fri Jul  1 04:51:53 2016
New Revision: 1750872

URL: http://svn.apache.org/viewvc?rev=1750872&view=rev
Log:
Use try-with-resources.

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java?rev=1750872&r1=1750871&r2=1750872&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
Fri Jul  1 04:51:53 2016
@@ -318,18 +318,18 @@ public class SftpFileSystem
 
         channel.setCommand(command);
         channel.setInputStream(null);
-        final InputStreamReader stream = new InputStreamReader(channel.getInputStream());
-        channel.setErrStream(System.err, true);
-        channel.connect();
-
-        // Read the stream
-        final char[] buffer = new char[EXEC_BUFFER_SIZE];
-        int read;
-        while ((read = stream.read(buffer, 0, buffer.length)) >= 0)
+        try (final InputStreamReader stream = new InputStreamReader(channel.getInputStream()))

         {
-            output.append(buffer, 0, read);
+            channel.setErrStream(System.err, true);
+            channel.connect();
+
+            // Read the stream
+            final char[] buffer = new char[EXEC_BUFFER_SIZE];
+            int read;
+            while ((read = stream.read(buffer, 0, buffer.length)) >= 0) {
+                output.append(buffer, 0, read);
+            }
         }
-        stream.close();
 
         // Wait until the command finishes (should not be long since we read the output stream)
         while (!channel.isClosed())



Mime
View raw message