private static String getPrompt(ClientChannel channel, ByteArrayOutputStream output, SshEndpoint endpoint) throws UnsupportedEncodingException, InterruptedException { while (!channel.isClosed()) { String response = new String(output.toByteArray(), "UTF-8"); if (response.trim().endsWith(endpoint.getShellPrompt())) { output.reset(); return SshShellOutputStringHelper.betweenBeforeLast(response, System.lineSeparator(), System.lineSeparator()); } // avoid cpu burning cycles Thread.sleep(endpoint.getSleepForShellPrompt()); } return null; } }
@Override public void write(int b) throws IOException { if (channel.isClosed() || channel.isClosing()) { throw new IOException("Channel (" + channel + ") is closing / closed on write single byte"); } if (b == (eofSignal & 0xff)) { log.info("Closing channel (" + channel + ") due to single byte EOF"); channel.close(true); } }
@Override public void write(int b) throws IOException { if (channel.isClosed() || channel.isClosing()) { throw new IOException("Channel (" + channel + ") is closing / closed on write single byte"); } if (b == (eofSignal & 0xff)) { log.info("Closing channel (" + channel + ") due to single byte EOF"); channel.close(true); } }
@Override public void write(int b) throws IOException { if (channel.isClosed() || channel.isClosing()) { throw new IOException("Channel (" + channel + ") is closing / closed on write single byte"); } if (b == (eofSignal & 0xff)) { log.info("Closing channel (" + channel + ") due to single byte EOF"); channel.close(true); } }
@Override public void write(byte[] b, int off, int len) throws IOException { if (channel.isClosed() || channel.isClosing()) { throw new IOException("Channel (" + channel + ") is closing / closed on write " + len + " bytes"); } if (len <= 0) { return; } int lastPos = off + len - 1; if ((b[lastPos] & 0xFF) == (eofSignal & 0xFF)) { log.info("Closing channel (" + channel + ") due to last byte EOF"); channel.close(true); } } }
@Override public void write(byte[] b, int off, int len) throws IOException { if (channel.isClosed() || channel.isClosing()) { throw new IOException("Channel (" + channel + ") is closing / closed on write " + len + " bytes"); } if (len <= 0) { return; } int lastPos = off + len - 1; if ((b[lastPos] & 0xFF) == (eofSignal & 0xFF)) { log.info("Closing channel (" + channel + ") due to last byte EOF"); channel.close(true); } } }
@Override public void write(byte[] b, int off, int len) throws IOException { if (channel.isClosed() || channel.isClosing()) { throw new IOException("Channel (" + channel + ") is closing / closed on write " + len + " bytes"); } if (len <= 0) { return; } int lastPos = off + len - 1; if ((b[lastPos] & 0xFF) == (eofSignal & 0xFF)) { log.info("Closing channel (" + channel + ") due to last byte EOF"); channel.close(true); } } }