System.out.print(new String(tmp, 0, i)); if (channel.isClosed()) { if (in.available() > 0) continue; System.out.println("exit-status: " + channel.getExitStatus());
if (channel.isClosed()) { if (in.available() > 0) continue; if (channel.getExitStatus() != 0)
if (channel.isClosed()) { if (in.available() > 0) continue;
if (channel.isClosed()) { if (in.available() > 0) continue;
public boolean isClosed() { if( m_channel != null ) { if( m_channel.isClosed() ) { // We've been disconnected, shut down stop(); } } return m_channel == null; }
public boolean isClosed() { if (m_channel != null) { if (m_channel.isClosed()) { // We've been disconnected, shut down stop(); } } return m_channel == null; }
public boolean isClosed() { if (m_channel != null) { if (m_channel.isClosed()) { // We've been disconnected, shut down stop(); } } return m_channel == null; }
/** * Blocks until the given channel is close or the timout is reached * * @param channel the channel to wait for * @param timoutInMs the timeout */ private static void waitForChannelClosure(Channel channel, long timoutInMs) { final long start = System.currentTimeMillis(); final long until = start + timoutInMs; try { while (!channel.isClosed() && System.currentTimeMillis() < until) { Thread.sleep(CLOSURE_WAIT_INTERVAL); } logger.trace("Time waited for channel closure: " + (System.currentTimeMillis() - start)); } catch (InterruptedException e) { logger.trace("Interrupted", e); } if (!channel.isClosed()) { logger.trace("Channel not closed in timely manner!"); } };
private static String logJsch(Channel channel, InputStream in) { StringBuilder builder = new StringBuilder(); try { byte[] tmp = new byte[1024]; while (true) { while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) break; builder.append((new String(tmp, 0, i))); } if (channel.isClosed()) { // LOGGER.debug("exit-status: " + channel.getExitStatus()); break; } } } catch (Exception ex) { LOGGER.error(ex); } return builder.toString(); }
private static String logJsch(Channel channel, InputStream in) { StringBuilder builder = new StringBuilder(); try { byte[] tmp = new byte[1024]; while (true) { while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) break; builder.append((new String(tmp, 0, i))); } if (channel.isClosed()) { // LOGGER.debug("exit-status: " + channel.getExitStatus()); break; } } } catch (Exception ex) { LOGGER.error(ex); } return builder.toString(); }
private static String logJsch(Channel channel, InputStream in) { StringBuilder builder = new StringBuilder(); try { byte[] tmp = new byte[1024]; while (true) { while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) break; builder.append((new String(tmp, 0, i))); } if (channel.isClosed()) { // LOGGER.debug("exit-status: " + channel.getExitStatus()); break; } } } catch (Exception ex) { LOGGER.error(ex); } return builder.toString(); }
private static String logJsch(Channel channel, InputStream in) { StringBuilder builder = new StringBuilder(); try { byte[] tmp = new byte[1024]; while (true) { while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) break; builder.append((new String(tmp, 0, i))); } if (channel.isClosed()) { // LOGGER.debug("exit-status: " + channel.getExitStatus()); break; } } } catch (Exception ex) { LOGGER.error(ex); } return builder.toString(); }
private static void logJsch(Channel channel, InputStream in) { try { byte[] tmp = new byte[1024]; while (true) { /* while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) break; LOGGER.debug(new String(tmp, 0, i)); } */ if (channel.isClosed()) { LOGGER.debug("exit-status: " + channel.getExitStatus()); break; } } } catch (Exception ex) { LOGGER.error(ex); } }
public void close() { closed = true; for (final Channel channel : channels) if (!channel.isClosed()) channel.disconnect(); channels.clear(); librarian.checkIn(this); }
public void onOutput(Channel channel) { try { StringBuffer pbsOutput = new StringBuffer(""); InputStream inputStream = channel.getInputStream(); byte[] tmp = new byte[1024]; do { while (inputStream.available() > 0) { int i = inputStream.read(tmp, 0, 1024); if (i < 0) break; pbsOutput.append(new String(tmp, 0, i)); } } while (!channel.isClosed()) ; String output = pbsOutput.toString(); this.setStdOutputString(output); } catch (IOException e) { logger.error(e.getMessage(), e); } }
public void onOutput(Channel channel) { try { InputStream inputStream = channel.getInputStream(); byte[] tmp = new byte[1024]; while (true) { while (inputStream.available() > 0) { int i = inputStream.read(tmp, 0, 1024); if (i < 0) break; System.out.print(new String(tmp, 0, i)); } if (channel.isClosed()) { System.out.println("exit-status: " + channel.getExitStatus()); break; } try { Thread.sleep(1000); } catch (Exception ignored) { } } } catch (IOException e) { logger.error(e.getMessage(), e); } }
@Override public long getLength() throws IOException { try { URI uri = new URI(encodeUriParts(getSourcePath())); if (channel == null || channel.isClosed()) { channel = getSessionForHost(uri).openChannel("sftp"); channel.connect(); } ChannelSftp sftpChannel = (ChannelSftp) channel; SftpATTRS stats = sftpChannel.lstat(decodeUriParts(uri.getRawPath())); return stats.getSize(); } catch (URISyntaxException ex) { Logger.getLogger(FileOrRendition.class.getName()).log(Level.SEVERE, null, ex); throw new IOException("Error parsing URL", ex); } catch (SftpException ex) { Logger.getLogger(FileOrRendition.class.getName()).log(Level.SEVERE, null, ex); throw new IOException("Error getting file stats", ex); } catch (JSchException ex) { Logger.getLogger(FileOrRendition.class.getName()).log(Level.SEVERE, null, ex); throw new IOException("Error opening SFTP channel", ex); } }
@Override public InputStream getStream() throws IOException { try { URI uri = new URI(encodeUriParts(getSourcePath())); if (channel == null || channel.isClosed()) { channel = getSessionForHost(uri).openChannel("sftp"); channel.connect(); } ChannelSftp sftpChannel = (ChannelSftp) channel; currentStream = sftpChannel.get(decodeUriParts(uri.getRawPath())); return currentStream; } catch (URISyntaxException ex) { Logger.getLogger(FileOrRendition.class.getName()).log(Level.SEVERE, null, ex); throw new IOException("Bad URI format", ex); } catch (JSchException ex) { Logger.getLogger(FileOrRendition.class.getName()).log(Level.SEVERE, null, ex); throw new IOException("Error with connection", ex); } catch (SftpException ex) { Logger.getLogger(FileOrRendition.class.getName()).log(Level.SEVERE, null, ex); throw new IOException("Error retrieving file", ex); } }
@Override public void disconnect() { try { if((channel != null) && !channel.isClosed()) { netconfAdapter.sendMessage(NetconfConstMessages.CLOSE_SESSION); isOk(netconfAdapter.receiveMessage()); } } catch(IOException e) { throw new RuntimeException("Error closing netconf device", e); } finally { netconfAdapter = null; if(channel != null) { channel.disconnect(); channel = null; } if(session != null) { session.disconnect(); session = null; } } }
private void testClose(TestContext context, Consumer<Term> closer) throws Exception { Async async = context.async(); termHandler = term -> { term.closeHandler(v -> { async.complete(); }); closer.accept(term); }; startShell(); Session session = createSession("paulo", "secret", false); session.connect(); Channel channel = session.openChannel("shell"); channel.connect(); while (channel.isClosed()) { Thread.sleep(10); } }