rhtyd commented on a change in pull request #3919: Handle EOFException during
VR Health Check
URL: https://github.com/apache/cloudstack/pull/3919#discussion_r386960568
##########
File path: utils/src/main/java/com/cloud/utils/ssh/SshHelper.java
##########
@@ -207,22 +206,18 @@ public static void scpTo(String host, int port, String
user, File pemKeyFile, St
if (canEndTheSshConnection(waitResultTimeoutInMs, sess,
conditions)) {
break;
}
-
}
- while (stdout.available() > 0) {
- currentReadBytes = stdout.read(buffer);
- sbResult.append(new String(buffer, 0, currentReadBytes));
+ while((currentReadBytes = stdout.read(buffer)) > 0) {
Review comment:
@Pearl1594 instead of `> 0` we probably want to check for readbytes `!= -1`.
For example: (comments only for your understanding)
```
currentReadBytes = stdout.read(buffer);
while (currentReadBytes >= 0) { // or check for != -1
sbResult.append(new String(buffer, 0, currentReadBytes));
currentReadBytes = stdout.read(buffer); // read() will return -1 on
eof/complete
}
```
The other option is to use a more modern java-way to use `BufferedReader`
for example like:
```
BufferedReader bufferedStdOut = new BufferedReader(stdout);
.... use
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services