I am using JSch to ssh to a Linux server and run a custom utility and checking response in java code. I see some random characters in response. The same looks fine while checking in Putty.
private String logResponse(Channel channel, InputStream in) throws IOException {
byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(tmp, 0, 1024);
if (i < 0)
break;
return new String(tmp, 0, i);
}
if (channel.isClosed()) {
break;
}
}
return "";
}
Printing the response using above method (erased some texts)
If it is used in subsequent methods or printed in files, it will display different random characters.
Could it be due to encoding? Kindly suggest if the above method can be tweaked. Many thanks.