You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2016/07/01 04:51:53 UTC
svn commit: r1750872 -
/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
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())