List of usage examples for java.io IOException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:org.wso2.carbon.javaee.tomee.scan.ASTomEEJarScanner.java
/** * Scan a URL for JARs with the optional extensions to look at all files * and all directories./*from w ww . j av a 2s. com*/ */ private void process(JarScannerCallback callback, URL url) throws IOException { if (log.isTraceEnabled()) { log.trace(sm.getString("jarScan.jarUrlStart", url)); } URLConnection conn = url.openConnection(); if (conn instanceof JarURLConnection) { callback.scan((JarURLConnection) conn); } else { String urlStr = url.toString(); if (urlStr.startsWith("file:") || urlStr.startsWith("jndi:")) { if (urlStr.endsWith(Constants.JAR_EXT)) { URL jarURL = new URL("jar:" + urlStr + "!/"); callback.scan((JarURLConnection) jarURL.openConnection()); } else { File f; try { f = new File(url.toURI()); if (f.isFile() && isScanAllFiles()) { // Treat this file as a JAR URL jarURL = new URL("jar:" + urlStr + "!/"); callback.scan((JarURLConnection) jarURL.openConnection()); } else if (f.isDirectory() && isScanAllDirectories()) { File metainf = new File(f.getAbsoluteFile() + File.separator + "META-INF"); if (metainf.isDirectory()) { callback.scan(f); } } } catch (URISyntaxException e) { // Wrap the exception and re-throw IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } } } } }
From source file:uk.ac.ox.webauth.WebKdcXmlRequest.java
/** * Post the request and return the response document. * @param body The request body to post. * @return the parsed XML response.//from w w w .ja v a 2 s .c o m * @throws IOException when something goes wrong. */ public Document doPost(String body) throws IOException { HttpClient client = new HttpClient(); PostMethod post = new PostMethod(url); post.setRequestEntity(new StringRequestEntity(body, "text/xml", null)); InputStream xml = null; Document doc = null; try { int rcode = client.executeMethod(post); xml = post.getResponseBodyAsStream(); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); doc = docBuilder.parse(xml); if (rcode != 200) { throw new IOException("Got response " + rcode + " when trying to post to URL " + url + " with request body:\n" + body); } } catch (ParserConfigurationException pce) { IOException ioe = new IOException("Could not create the XML parser to read the response."); ioe.initCause(pce); throw ioe; } catch (SAXException se) { IOException ioe = new IOException("Could not parse the XML response."); ioe.initCause(se); throw ioe; } finally { if (xml != null) { xml.close(); } post.releaseConnection(); } return doc; }
From source file:org.jboss.spring.vfs.VFSResource.java
public URI getURI() throws IOException { try {//from www . ja v a 2s .c o m return VFSUtil.invokeMethodWithExpectedExceptionType(VFSUtil.VIRTUAL_FILE_METHOD_TO_URI, file, URISyntaxException.class); } catch (URISyntaxException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } }
From source file:ch.cyberduck.core.cf.CFSessionKeystone.java
@Override protected void login(final LoginController controller, final Credentials credentials) throws IOException { final FilesClientKeystone client = this.getClient(); client.setUserName(credentials.getUsername()); client.setPassword(credentials.getPassword()); try {//from w w w . j ava 2 s . c om if (!client.login()) { this.message(Locale.localizedString("Login failed", "Credentials")); controller.fail(host.getProtocol(), credentials); this.login(); } } // catch (HttpException e) { IOException failure = new IOException(e.getMessage()); failure.initCause(e); throw failure; } }
From source file:org.codehaus.mojo.mrm.impl.digest.MD5DigestFileEntry.java
/** * Generates the digest.//from w ww.j a va2 s. co m * * @return the digest. * @throws IOException if the backing entry could not be read. * @since 1.0 */ private byte[] getContent() throws IOException { InputStream is = null; try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.reset(); byte[] buffer = new byte[8192]; int read; try { is = entry.getInputStream(); while ((read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } } catch (IOException e) { if (is != null) { throw e; } } final String md5 = StringUtils.leftPad(new BigInteger(1, digest.digest()).toString(16), 32, "0"); return md5.getBytes(); } catch (NoSuchAlgorithmException e) { IOException ioe = new IOException("Unable to calculate hash"); ioe.initCause(e); throw ioe; } finally { IOUtils.closeQuietly(is); } }
From source file:org.ardverk.daap.nio.DaapRequestReaderNIO.java
public DaapRequest read() throws IOException { DaapRequest ret = null;/*from w ww . j a v a 2 s . co m*/ if (pending.isEmpty() == false) ret = pending.removeFirst(); String line = null; while ((line = lineReader.read(in, connection.getReadChannel())) != null) { bytesRead += in.position(); if (requestLine == null) { requestLine = line; } else { int p = line.indexOf(':'); if (p == -1) { requestLine = null; headers.clear(); lineReader = null; throw new IOException("Malformed Header"); } String name = line.substring(0, p).trim(); String value = line.substring(++p).trim(); headers.add(new BasicHeader(name, value)); } } if (lineReader.isComplete()) { DaapRequest request = null; try { request = new DaapRequest(connection, requestLine); request.addHeaders(headers); } catch (URISyntaxException e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } finally { requestLine = null; headers.clear(); } if (ret == null) { ret = request; } else { pending.addLast(request); } } else if (headers.size() >= 64) { requestLine = null; headers.clear(); throw new IOException("Header too large"); } return ret; }
From source file:com.adito.vfs.webdav.methods.COPY.java
/** * <p>/*from w w w .j a v a2 s . co m*/ * Process the <code>COPY</code> method. * </p> * * @throws IOException */ public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException { String handle = VFSLockManager.getNewHandle(); VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), false, true, handle); String action = (String) transaction.getRequest().getMethod(); VFSResource dest = null; try { URI target = transaction.getDestination(); if (target == null) throw new DAVException(412, "No destination"); if (log.isDebugEnabled()) log.debug("Target " + target.getPath()); try { DAVProcessor processor = DAVServlet.getDAVProcessor(transaction.getRequest()); dest = processor.getRepository().getResource(resource.getLaunchSession(), target.getPath(), transaction.getCredentials()/*, transaction*/); VFSLockManager.getInstance().lock(dest, transaction.getSessionInfo(), true, false, handle); } catch (Exception ex) { log.error("Failed to get resource. ", ex); transaction.setStatus(500); return; } int depth = transaction.getDepth(); boolean recursive = false; if (depth == 0) { recursive = false; } else if (depth == DAVTransaction.INFINITY) { recursive = true; } else { throw new DAVException(412, "Invalid Depth specified"); } try { resource.copy(dest, transaction.getOverwrite(), recursive); transaction.setStatus(204); } catch (DAVMultiStatus multistatus) { multistatus.write(transaction); } if (action.equals("COPY")) { resource.getMount().resourceCopy(resource, dest, transaction, null); } } catch (Exception e) { if (action.equals("COPY")) { resource.getMount().resourceCopy(resource, dest, transaction, e); } IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } finally { VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle); } }
From source file:org.codehaus.mojo.mrm.impl.digest.SHA1DigestFileEntry.java
/** * Generates the digest.//w ww.j a va 2 s. co m * * @return the digest. * @throws IOException if the backing entry could not be read. * @since 1.0 */ private byte[] getContent() throws IOException { InputStream is = null; try { MessageDigest digest = MessageDigest.getInstance("SHA1"); digest.reset(); byte[] buffer = new byte[8192]; int read; try { is = entry.getInputStream(); while ((read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } } catch (IOException e) { if (is != null) { throw e; } } final String md5 = StringUtils.leftPad(new BigInteger(1, digest.digest()).toString(16), 40, "0"); return md5.getBytes(); } catch (NoSuchAlgorithmException e) { IOException ioe = new IOException("Unable to calculate hash"); ioe.initCause(e); throw ioe; } finally { IOUtils.closeQuietly(is); } }
From source file:org.apache.maven.doxia.module.fo.FoConfiguration.java
/** * Load configuration parameters from a File. * * @param configFile the configuration file. * * @throws java.io.IOException if the File cannot be read * or some error occurs when initializing the configuration parameters. * * @since 1.1.1// w w w . j ava 2 s . c o m */ public void load(File configFile) throws IOException { config.clear(); try { config.load(configFile); } catch (ConfigurationException cex) { IOException ioe = new IOException(); ioe.initCause(cex); throw ioe; } loadDefaultConfig(); // this adds default values that are missing from above }