List of usage examples for java.util NoSuchElementException getCause
public synchronized Throwable getCause()
From source file:edu.gmu.isa681.ctn.EncodedChannel.java
private Encodeable recv(Class<? extends Encodeable> type) throws IOException, UnexpectedTypeException { try {/* w w w .j a v a 2s . c o m*/ sin.useDelimiter(DELIMITER); String encoded = sin.next(); return decode(encoded, type); } catch (NoSuchElementException ex) { throw new IOException(ex.getCause()); } }
From source file:ch.cyberduck.core.worker.ConcurrentTransferWorker.java
@Override protected Session<?> borrow() throws BackgroundException { try {// ww w .ja v a 2 s . c om if (this.isCanceled()) { throw new ConnectionCanceledException(); } Session session; while (true) { try { session = pool.borrowObject(); break; } catch (NoSuchElementException e) { if (this.isCanceled()) { throw new ConnectionCanceledException(e); } if (e.getCause() instanceof BackgroundException) { final BackgroundException cause = (BackgroundException) e.getCause(); log.warn(String.format("Failure %s obtaining connection for %s", cause, this)); if (diagnostics.determine(cause) == FailureDiagnostics.Type.network) { // Downgrade pool to single connection final int max = pool.getMaxTotal() - 1; log.warn(String.format("Lower maximum pool size to %d connections.", max)); pool.setMaxTotal(max); pool.setMaxIdle(pool.getMaxIdle() - 1); if (this.retry()) { if (log.isInfoEnabled()) { log.info(String.format("Connect failed with failure %s", e)); } // This is an automated retry. Wait some time first. this.pause(); if (!isCanceled()) { repeat.set(repeat.get() + 1); // Retry to connect continue; } } } throw cause; } if (null == e.getCause()) { log.warn(String.format("Timeout borrowing session from pool %s. Wait for another %dms", pool, BORROW_MAX_WAIT_INTERVAL)); // Timeout continue; } log.error(String.format("Borrowing session from pool %s failed with %s", pool, e)); throw new BackgroundException(e); } } if (log.isInfoEnabled()) { log.info(String.format("Borrow session %s from pool", session)); } return session; } catch (BackgroundException e) { throw e; } catch (Exception e) { if (e.getCause() instanceof BackgroundException) { throw ((BackgroundException) e.getCause()); } throw new BackgroundException(e.getMessage(), e); } }
From source file:org.dspace.license.CCLookup.java
/** * Passes a set of "answers" to the web service and retrieves a license. * * @param licenseId The identifier of the license class being requested. * @param answers A Map containing the answers to the license fields; * each key is the identifier of a LicenseField, with the value * containing the user-supplied answer. * @param lang The language to request localized elements in. * * @throws IOException//from ww w . ja v a2s . c om * * @see CCLicense * @see Map */ public void issue(String licenseId, Map answers, String lang) throws IOException { // Determine the issue URL String issueUrl = this.cc_root + "/license/" + licenseId + "/issue"; // Assemble the "answers" document String answer_doc = "<answers>\n<locale>" + lang + "</locale>\n" + "<license-" + licenseId + ">\n"; Iterator keys = answers.keySet().iterator(); try { String current = (String) keys.next(); while (true) { answer_doc += "<" + current + ">" + (String) answers.get(current) + "</" + current + ">\n"; current = (String) keys.next(); } } catch (NoSuchElementException e) { // exception indicates we've iterated through the // entire collection; just swallow and continue } // answer_doc += "<jurisdiction></jurisidiction>\n"; FAILS with jurisdiction argument answer_doc += "</license-" + licenseId + ">\n</answers>\n"; String post_data; try { post_data = URLEncoder.encode("answers", "UTF-8") + "=" + URLEncoder.encode(answer_doc, "UTF-8"); } catch (UnsupportedEncodingException e) { return; } URL post_url; try { post_url = new URL(issueUrl); } catch (MalformedURLException e) { return; } URLConnection connection = post_url.openConnection(); // this will not be needed after I'm done TODO: remove connection.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); writer.write(post_data); writer.flush(); // end TODO try { // parsing document from input stream java.io.InputStream stream = connection.getInputStream(); this.license_doc = this.parser.build(stream); } catch (JDOMException jde) { log.warn(jde.getMessage()); } catch (Exception e) { log.warn(e.getCause()); } return; }