本文整理汇总了Java中com.jcraft.jsch.JSchException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java JSchException.getCause方法的具体用法?Java JSchException.getCause怎么用?Java JSchException.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcraft.jsch.JSchException
的用法示例。
在下文中一共展示了JSchException.getCause方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.jcraft.jsch.JSchException; //导入方法依赖的package包/类
public JSch build() throws JSchException {
LOGGER.debug("Initializing JSch Logger");
JSch.setLogger(new JschLogger());
final JSch jsch = new JSch();
try {
if (null != knownHostsFileName && new File(knownHostsFileName).exists()) {
jsch.setKnownHosts(knownHostsFileName);
}
if (null != privateKeyFileName && new File(privateKeyFileName).exists()) {
jsch.addIdentity(privateKeyFileName);
}
} catch (JSchException e) {
LOGGER.error("Could not access known hosts or private key file.", e);
if (!(e.getCause() instanceof FileNotFoundException)) {
throw new JSchException();
}
}
return jsch;
}
示例2: start
import com.jcraft.jsch.JSchException; //导入方法依赖的package包/类
private synchronized static ChannelStreams start(final JSchWorker<ChannelStreams> worker, final ExecutionEnvironment env, final int attempts) throws IOException, JSchException, InterruptedException {
int retry = attempts;
while (retry-- > 0) {
try {
return worker.call();
} catch (JSchException ex) {
String message = ex.getMessage();
Throwable cause = ex.getCause();
if (cause != null && cause instanceof NullPointerException) {
// Jsch bug... retry?
log.log(Level.INFO, "JSch exception opening channel to " + env + ". Retrying", ex); // NOI18N
} else if ("java.io.InterruptedIOException".equals(message)) { // NOI18N
log.log(Level.INFO, "JSch exception opening channel to " + env + ". Retrying in 0.5 seconds", ex); // NOI18N
try {
Thread.sleep(500);
} catch (InterruptedException ex1) {
Thread.currentThread().interrupt();
break;
}
} else if ("channel is not opened.".equals(message)) { // NOI18N
log.log(Level.INFO, "JSch exception opening channel to " + env + ". Reconnecting and retrying", ex); // NOI18N
// Now reconnect disconnects old session and creates new, so this might help
ConnectionManagerAccessor.getDefault().reconnect(env);
} else {
throw ex;
}
} catch (NullPointerException npe) {
// Jsch bug... retry? ;)
log.log(Level.FINE, "Exception from JSch", npe); // NOI18N
}
}
throw new IOException("Failed to execute " + worker.toString()); // NOI18N
}