Example usage for java.io IOException initCause

List of usage examples for java.io IOException initCause

Introduction

In this page you can find the example usage for java.io IOException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:org.jscep.server.ScepServlet.java

private CMSSignedData getMessageData(final List<X509Certificate> certs)
        throws IOException, CMSException, GeneralSecurityException {
    CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
    JcaCertStore store;//www  .ja v  a 2 s. c om
    try {
        store = new JcaCertStore(certs);
    } catch (CertificateEncodingException e) {
        IOException ioe = new IOException();
        ioe.initCause(e);

        throw ioe;
    }
    generator.addCertificates(store);
    return generator.generate(new CMSAbsentContent());
}

From source file:org.apache.rahas.Token.java

private OMElement convertStringToOMElement(String stringElement) throws IOException {

    if (null == stringElement || stringElement.trim().equals("")) {
        return null;
    }/*from ww  w .j  a  v a 2  s .  c  om*/

    try {
        Reader in = new StringReader(stringElement);
        XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
        StAXOMBuilder builder = new StAXOMBuilder(parser);
        OMElement documentElement = builder.getDocumentElement();

        XMLStreamReader llomReader = documentElement.getXMLStreamReader();
        OMFactory doomFactory = DOOMAbstractFactory.getOMFactory();
        StAXOMBuilder doomBuilder = new StAXOMBuilder(doomFactory, llomReader);
        return doomBuilder.getDocumentElement();

    } catch (XMLStreamException e) {
        log.error("Cannot convert de-serialized string to OMElement. Could not create XML stream.", e);
        // IOException only has a constructor supporting exception chaining starting with Java 1.6
        IOException ex = new IOException(
                "Cannot convert de-serialized string to OMElement. Could not create XML stream.");
        ex.initCause(e);
        throw ex;
    }
}

From source file:org.apache.hadoop.mapred.StatusHttpServer.java

/**
 * Start the server. Does not wait for the server to start.
 *//*  ww  w  . ja  v  a  2 s  .  c om*/
public void start() throws IOException {
    try {
        while (true) {
            try {
                webServer.start();
                break;
            } catch (org.mortbay.util.MultiException ex) {
                // if the multi exception contains ONLY a bind exception,
                // then try the next port number.
                boolean needNewPort = false;
                if (ex.size() == 1) {
                    Exception sub = ex.getException(0);
                    if (sub instanceof java.net.BindException) {
                        if (!findPort)
                            throw sub; // java.net.BindException
                        needNewPort = true;
                    }
                }
                if (!needNewPort)
                    throw ex;
                listener.setPort(listener.getPort() + 1);
            }
        }
    } catch (IOException ie) {
        throw ie;
    } catch (Exception e) {
        IOException ie = new IOException("Problem starting http server");
        ie.initCause(e);
        throw ie;
    }
}

From source file:ch.cyberduck.core.cf.CFPath.java

@Override
public InputStream read(final TransferStatus status) throws IOException {
    try {//from   w w  w  .  j a v a 2  s  .  c  o m
        if (status.isResume()) {
            return this.getSession().getClient().getObjectAsRangedStream(this.getContainerName(), this.getKey(),
                    status.getCurrent(), status.getLength());
        }
        return this.getSession().getClient().getObjectAsStream(this.getContainerName(), this.getKey());
    } catch (HttpException e) {
        IOException failure = new IOException(e.getMessage());
        failure.initCause(e);
        throw failure;
    }
}

From source file:org.jscep.server.ScepServlet.java

private void doGetCaCert(final HttpServletRequest req, final HttpServletResponse res) throws Exception {
    final List<X509Certificate> certs = doGetCaCertificate(req.getParameter(MSG_PARAM));
    final byte[] bytes;
    if (certs.size() == 0) {
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "GetCaCert failed to obtain CA from store");
        bytes = new byte[0];
    } else if (certs.size() == 1) {
        res.setHeader("Content-Type", "application/x-x509-ca-cert");
        bytes = certs.get(0).getEncoded();
    } else {// w w w .ja v  a2s .  c  om
        res.setHeader("Content-Type", "application/x-x509-ca-ra-cert");
        CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
        JcaCertStore store;
        try {
            store = new JcaCertStore(certs);
        } catch (CertificateEncodingException e) {
            IOException ioe = new IOException();
            ioe.initCause(e);

            throw ioe;
        }
        generator.addCertificates(store);
        CMSSignedData degenerateSd = generator.generate(new CMSAbsentContent());
        bytes = degenerateSd.getEncoded();
    }

    res.getOutputStream().write(bytes);
    res.getOutputStream().close();
}

From source file:org.jscep.server.ScepServlet.java

private void doGetNextCaCert(final HttpServletRequest req, final HttpServletResponse res) throws Exception {
    res.setHeader("Content-Type", "application/x-x509-next-ca-cert");

    List<X509Certificate> certs = getNextCaCertificate(req.getParameter(MSG_PARAM));

    if (certs.size() == 0) {
        res.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "GetNextCACert Not Supported");
    } else {// www. j a  v a  2 s  .c o  m
        CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
        JcaCertStore store;
        try {
            store = new JcaCertStore(certs);
        } catch (CertificateEncodingException e) {
            IOException ioe = new IOException();
            ioe.initCause(e);

            throw ioe;
        }
        generator.addCertificates(store);
        DigestCalculatorProvider digestProvider = new JcaDigestCalculatorProviderBuilder().build();
        SignerInfoGeneratorBuilder infoGenBuilder = new SignerInfoGeneratorBuilder(digestProvider);
        X509CertificateHolder certHolder = new X509CertificateHolder(getRecipient().getEncoded());
        ContentSigner contentSigner = new JcaContentSignerBuilder("SHA1withRSA").build(getRecipientKey());
        SignerInfoGenerator infoGen = infoGenBuilder.build(contentSigner, certHolder);
        generator.addSignerInfoGenerator(infoGen);

        CMSSignedData degenerateSd = generator.generate(new CMSAbsentContent());
        byte[] bytes = degenerateSd.getEncoded();

        res.getOutputStream().write(bytes);
        res.getOutputStream().close();
    }
}

From source file:com.uphyca.kitkat.storage.internal.impl.LiveSdkSkyDriveClient.java

@Override
public String upload(String path, String name, File file) throws IOException {
    initializeIfNecessary();// w ww .  jav  a2 s  . c o m
    if (mLiveConnectClient == null) {
        return null;
    }

    try {
        LiveOperation post = mLiveConnectClient.upload(path, name, file, OverwriteOption.Overwrite);
        JSONObject result = post.getResult();
        if (result.has(JsonKeys.ERROR)) {
            JSONObject error = result.optJSONObject(JsonKeys.ERROR);
            String message = error.optString(JsonKeys.MESSAGE);
            IOException ioException = new IOException(message);
            ioException.fillInStackTrace();
            throw ioException;
        }
        try {
            return result.getString(JsonKeys.ID);
        } catch (JSONException e) {
            IOException ioException = new IOException(e.getMessage());
            ioException.initCause(e);
            throw ioException;
        }
    } catch (LiveOperationException e) {
        IOException ioException = new IOException(e.getMessage());
        ioException.initCause(e);
        throw ioException;
    }
}

From source file:com.uphyca.kitkat.storage.internal.impl.LiveSdkSkyDriveClient.java

@Override
public String mkdir(String path, String name) throws IOException {
    initializeIfNecessary();/*w ww .j av a2  s .  com*/
    if (mLiveConnectClient == null) {
        return null;
    }

    Map<String, String> folder = new HashMap<>();
    folder.put(JsonKeys.NAME, name);
    folder.put(JsonKeys.DESCRIPTION, null);
    try {
        LiveOperation post = mLiveConnectClient.post(path, new JSONObject(folder));
        JSONObject result = post.getResult();
        if (result.has(JsonKeys.ERROR)) {
            JSONObject error = result.optJSONObject(JsonKeys.ERROR);
            String message = error.optString(JsonKeys.MESSAGE);
            IOException ioException = new IOException(message);
            ioException.fillInStackTrace();
            throw ioException;
        }
        try {
            return result.getString(JsonKeys.ID);
        } catch (JSONException e) {
            IOException ioException = new IOException(e.getMessage());
            ioException.initCause(e);
            throw ioException;
        }
    } catch (LiveOperationException e) {
        IOException ioException = new IOException(e.getMessage());
        ioException.initCause(e);
        throw ioException;
    }
}

From source file:org.simplx.args.MainArgs.java

@SuppressWarnings({ "TypeMayBeWeakened" })
private static IOException ioException(String opt, String path, IOException e) {

    IOException ne = new IOException("-" + opt + " " + path);
    ne.initCause(e);
    return ne;/*from w  w w .  ja v  a 2  s.  c  om*/
}

From source file:org.apache.jackrabbit.core.fs.db.OracleFileSystem.java

/**
 * {@inheritDoc}/*from   w w  w  .jav a  2  s. co  m*/
 * <p/>
 * Overridden because we need to use <code>oracle.sql.BLOB</code>
 * and <code>PreparedStatement#setBlob</code> instead of just
 * <code>PreparedStatement#setBinaryStream</code>.
 */
public OutputStream getOutputStream(final String filePath) throws FileSystemException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }

    FileSystemPathUtil.checkFormat(filePath);

    final String parentDir = FileSystemPathUtil.getParentDir(filePath);
    final String name = FileSystemPathUtil.getName(filePath);

    if (!isFolder(parentDir)) {
        throw new FileSystemException("path not found: " + parentDir);
    }

    if (isFolder(filePath)) {
        throw new FileSystemException("path denotes folder: " + filePath);
    }

    try {
        TransientFileFactory fileFactory = TransientFileFactory.getInstance();
        final File tmpFile = fileFactory.createTransientFile("bin", null, null);

        return new FilterOutputStream(new FileOutputStream(tmpFile)) {

            public void write(byte[] bytes, int off, int len) throws IOException {
                out.write(bytes, off, len);
            }

            public void close() throws IOException {
                out.flush();
                ((FileOutputStream) out).getFD().sync();
                out.close();

                InputStream in = null;
                Blob blob = null;
                try {
                    if (isFile(filePath)) {
                        synchronized (updateDataSQL) {
                            long length = tmpFile.length();
                            in = new FileInputStream(tmpFile);
                            blob = createTemporaryBlob(in);
                            executeStmt(updateDataSQL, new Object[] { blob,
                                    new Long(System.currentTimeMillis()), new Long(length), parentDir, name });
                        }
                    } else {
                        synchronized (insertFileSQL) {
                            long length = tmpFile.length();
                            in = new FileInputStream(tmpFile);
                            blob = createTemporaryBlob(in);
                            executeStmt(insertFileSQL, new Object[] { parentDir, name, blob,
                                    new Long(System.currentTimeMillis()), new Long(length) });
                        }
                    }
                } catch (Exception e) {
                    IOException ioe = new IOException(e.getMessage());
                    ioe.initCause(e);
                    throw ioe;
                } finally {
                    if (blob != null) {
                        try {
                            freeTemporaryBlob(blob);
                        } catch (Exception e1) {
                        }
                    }
                    IOUtils.closeQuietly(in);
                    // temp file can now safely be removed
                    tmpFile.delete();
                }
            }
        };
    } catch (Exception e) {
        String msg = "failed to open output stream to file: " + filePath;
        log.error(msg, e);
        throw new FileSystemException(msg, e);
    }
}