本文整理匯總了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
}