- int length = cmd.length();
- int i = -1;
- int nchars = 300000;
- int ncharsTotalSent = 0;
- int ncharsSent = 0;
-
- debugLog.printRTAriDebug(fn, "Length of cmd is:" + length); // 2,937,706
- debugLog.printRTAriDebug(fn, "Length of cmd is:" + length); // 2,937,706
- try {
- if (length > 600000) {
- int timeout = 9000;
- for (i = 0; i < length; i += nchars) {
- String Cmd = cmd.substring(i, Math.min(length, i + nchars));
- ncharsSent = Cmd.length();
- ncharsTotalSent = ncharsTotalSent + Cmd.length();
- debugLog.printRTAriDebug(fn, "i=" + i + " Sending Cmd: ncharsSent=" + ncharsSent);
- dos.writeBytes(Cmd);
- dos.flush();
- try {
- debugLog.printRTAriDebug(fn, ":::i=" + i + " length=" + length);
- if (ncharsSent < length) {
- receiveUntilBufferFlush(ncharsSent, timeout, "buffer flush i=" + i);
- } else {
- debugLog.printRTAriDebug(fn, "i=" + i + " No Waiting this time....");
- dos.flush();
- }
- } catch (Exception e) {
- debugLog.printRTAriDebug(fn, "Caught an Exception: Nothing to flush out.");
+ }
+
+ private void sendSshCommand(@Nonnull String originalCommand, @Nonnull DataOutputStream channelOutputStream)
+ throws IOException {
+ String fn = "SshJcraftWrapper.sendSshCommand";
+ String command = enhanceCommandWithEOL(originalCommand);
+ int length = command.length();
+ int charsChunkSize = 300000;
+ int charsTotalSent = 0;
+
+ appendToFile(debugLogFileName, fn + ": Sending: '" + command);
+ DebugLog.printRTAriDebug(fn, "Length of command is:" + length); // 2,937,706
+ if (isCmdLengthEnoughToSendInChunks(length, charsChunkSize)) {
+ int timeout = 9000;
+ for (int i = 0; i < length; i += charsChunkSize) {
+ String commandChunk = command.substring(i, Math.min(length, i + charsChunkSize));
+ int numCharsSentInChunk = commandChunk.length();
+ charsTotalSent = charsTotalSent + commandChunk.length();
+ DebugLog.printRTAriDebug(fn, "i=" + i + " Sending command: ncharsSent=" + numCharsSentInChunk);
+ channelOutputStream.writeBytes(commandChunk);
+ channelOutputStream.flush();
+ try {
+ DebugLog.printRTAriDebug(fn, ":::i=" + i + " length=" + length);
+ if (numCharsSentInChunk < length) {
+ receiveUntilBufferFlush(numCharsSentInChunk, timeout, "buffer flush i=" + i);
+ } else {
+ DebugLog.printRTAriDebug(fn, "i=" + i + " No Waiting this time....");
+ channelOutputStream.flush();