Example usage for java.io IOException getCause

List of usage examples for java.io IOException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.orcid.core.TestXmlValidity.java

@Test
public void testAllOrcidMessages() throws IOException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("classpath*:**/*message-latest.xml");
    for (Resource resource : resources) {
        LOG.info("Found resource: {}", resource);
        InputStream is = null;//w  ww  .  j a  v a  2 s  .  c  o  m
        try {
            is = resource.getInputStream();
            OrcidMessage message = (OrcidMessage) unmarshaller.unmarshal(is);
            validationManager = getValidationManager(message.getMessageVersion());
            validationManager.validateMessage(message);
        } catch (IOException e) {
            Assert.fail("Unable to read resource: " + resource + "\n" + e);
        } catch (JAXBException e) {
            Assert.fail("ORCID message is not well formed: " + resource + "\n" + e);
        } catch (OrcidValidationException e) {
            Assert.fail("Validation failed: " + resource + "\n" + e.getCause());
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}

From source file:com.relicum.ipsum.Locale.PropertyManager.java

/**
 * Write properties to the specified file.
 *
 * @param file the {@link java.io.File} to write the properties to.
 * @throws IOException the {@link java.io.IOException} if their was a problem writing to the file.
 *///from  ww w  . j av a  2  s  .  c o m
public void writeToFile(File file) throws IOException {

    boolean b;
    b = file.exists();
    if (!b) {

        try {
            b = file.createNewFile();
            if (!b)
                throw new RuntimeException("Can not create file at " + file.getPath());
            writer = new FileWriter(file);
            properties.store(writer, "Plugin Messages");
        } catch (IOException e) {
            log.log(Level.SEVERE, e.getMessage(), e.getCause());
            throw e;

        } finally {
            if (writer != null) {
                writer.flush();
                writer.close();
            }
        }
    }

}

From source file:org.apache.hadoop.hbase.rest.client.TestXmlParsing.java

@Test
public void testFailOnExternalEntities() throws Exception {
    final String externalEntitiesXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + " <!DOCTYPE foo [ <!ENTITY xxe SYSTEM \"/tmp/foo\"> ] >"
            + " <ClusterVersion>&xee;</ClusterVersion>";
    Client client = mock(Client.class);
    RemoteAdmin admin = new RemoteAdmin(client, HBaseConfiguration.create(), null);
    Response resp = new Response(200, null, externalEntitiesXml.getBytes());

    when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp);

    try {/*from  www .ja va  2s  .  c o m*/
        admin.getClusterVersion();
        fail("Expected getClusterVersion() to throw an exception");
    } catch (IOException e) {
        assertEquals(
                "Cause of exception ought to be a failure to parse the stream due to our "
                        + "invalid external entity. Make sure this isn't just a false positive due to "
                        + "implementation. see HBASE-19020.",
                UnmarshalException.class, e.getCause().getClass());
        final String exceptionText = StringUtils.stringifyException(e);
        final String expectedText = "\"xee\"";
        LOG.debug("exception text: '" + exceptionText + "'", e);
        assertTrue("Exception does not contain expected text", exceptionText.contains(expectedText));
    }
}

From source file:com.compomics.colims.client.controller.AnalyticalRunsSearchSettingsController.java

/**
 * Delete the database entity (project, experiment, analytical runs) from
 * the database. Shows a confirmation dialog first. When confirmed, a
 * DeleteDbTask message is sent to the DB task queue. A message dialog is
 * shown in case the queue cannot be reached or in case of an IOException
 * thrown by the sendDbTask method.//from  w  w  w  .j  a v  a  2  s.c  o  m
 *
 * @param entity the entity to delete
 * @param dbEntityClass the database entity class
 * @return true if the delete task is confirmed.
 */
private boolean deleteEntity(final DatabaseEntity entity, final Class dbEntityClass) {
    boolean deleteConfirmation = false;

    //check delete permissions
    if (userBean.getDefaultPermissions().get(DefaultPermission.DELETE)) {
        int option = JOptionPane.showConfirmDialog(mainController.getMainFrame(),
                "Are you sure? This will remove all underlying database relations (spectra, psm's, ...) as well."
                        + System.lineSeparator() + "A delete task will be sent to the database task queue.",
                "Delete " + dbEntityClass.getSimpleName() + " confirmation.", JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            //check connection
            if (queueManager.isReachable()) {
                DeleteDbTask deleteDbTask = new DeleteDbTask(dbEntityClass, entity.getId(),
                        userBean.getCurrentUser().getId());
                try {
                    dbTaskProducer.sendDbTask(deleteDbTask);
                    deleteConfirmation = true;
                } catch (IOException e) {
                    LOGGER.error(e, e.getCause());
                    eventBus.post(new UnexpectedErrorMessageEvent(e.getMessage()));
                }
            } else {
                eventBus.post(new StorageQueuesConnectionErrorMessageEvent(queueManager.getBrokerName(),
                        queueManager.getBrokerUrl(), queueManager.getBrokerJmxUrl()));
            }
        }
    } else {
        mainController.showPermissionErrorDialog(
                "Your user doesn't have rights to delete this " + entity.getClass().getSimpleName());
    }

    return deleteConfirmation;
}

From source file:org.flockdata.client.FdTemplate.java

private String writeEntitiesAmqp(Collection<EntityInputBean> entityInputs) throws FlockException {
    try {//from  w w  w .  ja  v a  2 s  .c  om
        // DAT-373
        fdRabbitClient.publish(entityInputs);
    } catch (IOException ioe) {
        logger.error(ioe.getLocalizedMessage());
        throw new FlockException("IO Exception", ioe.getCause());
    }
    return "OK";

}

From source file:net.oneandone.stool.Start.java

private void ping(Stage stage) throws IOException, SAXException, URISyntaxException, InterruptedException {
    URI uri;/*w  w  w .j a va  2 s  .c o  m*/
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setConnectTimeout(500);
    console.info.println("Ping'n Applications.");
    Thread.sleep(2000);
    for (String url : stage.urlMap().values()) {
        if (url.startsWith("http://")) {
            uri = new URI(url);
            console.verbose.println("Opening connection to " + url);
            try {
                requestFactory.createRequest(uri, HttpMethod.GET).execute();
            } catch (IOException e) {
                console.verbose.println("Opening connection failed. " + e.getCause());
            }
        }
    }

}

From source file:com.emcopentechnologies.viprcloudstorage.WAStorageClient.java

/**
 * Uploads files to ViPR Cloud Storage.//from   w  ww . j  a  va  2s  .com
 * 
 * @param listener
 * @param build
 * @param StorageAccountInfo
 *            storage account information.
 * @param expContainerName
 *            container name.
 * @param cntPubAccess
 *            denotes if container is publicly accessible.
 * @param expFP
 *            File Path in ant glob syntax relative to CI tool workspace.
 * @param expVP
 *            Virtual Path of blob container.
 * @return filesUploaded number of files that are uploaded.
 * @throws WAStorageException
 * @throws Exception
 */
public static int upload(AbstractBuild<?, ?> build, BuildListener listener, StorageAccountInfo strAcc,
        String expContainerName, boolean cntPubAccess, boolean cleanUpContainer, String expFP, String expVP,
        List<CloudBlob> blobs) throws WAStorageException {

    CloudBlockBlob blob = null;
    int filesUploaded = 0; // Counter to track no. of files that are uploaded

    try {
        FilePath workspacePath = build.getWorkspace();
        if (workspacePath == null) {
            listener.getLogger().println(Messages.CloudStorageBuilder_ws_na());
            return filesUploaded;
        }
        StringTokenizer strTokens = new StringTokenizer(expFP, fpSeparator);
        FilePath[] paths = null;

        listener.getLogger().println(Messages.WAStoragePublisher_uploading());

        CloudBlobContainer container = WAStorageClient.getBlobContainerReference(strAcc.getStorageAccName(),
                strAcc.getStorageAccountKey(), strAcc.getBlobEndPointURL(), expContainerName, true, true,
                cntPubAccess);

        // Delete previous contents if cleanup is needed
        if (cleanUpContainer) {
            deleteContents(container);
        }

        while (strTokens.hasMoreElements()) {
            String fileName = strTokens.nextToken();

            String embeddedVP = null;

            if (fileName != null) {
                int embVPSepIndex = fileName.indexOf("::");

                // Separate fileName and Virtual directory name
                if (embVPSepIndex != -1) {
                    if (fileName.length() > embVPSepIndex + 1) {
                        embeddedVP = fileName.substring(embVPSepIndex + 2, fileName.length());

                        if (Utils.isNullOrEmpty(embeddedVP)) {
                            embeddedVP = null;
                        }

                        if (embeddedVP != null && !embeddedVP.endsWith(Utils.FWD_SLASH)) {
                            embeddedVP = embeddedVP + Utils.FWD_SLASH;
                        }
                    }
                    fileName = fileName.substring(0, embVPSepIndex);
                }
            }

            if (Utils.isNullOrEmpty(fileName)) {
                return filesUploaded;
            }

            FilePath fp = new FilePath(workspacePath, fileName);

            if (fp.exists() && !fp.isDirectory()) {
                paths = new FilePath[1];
                paths[0] = fp;
            } else {
                paths = workspacePath.list(fileName);
            }

            if (paths.length != 0) {
                for (FilePath src : paths) {
                    if (Utils.isNullOrEmpty(expVP) && Utils.isNullOrEmpty(embeddedVP)) {
                        blob = container.getBlockBlobReference(src.getName());
                    } else {
                        String prefix = expVP;

                        if (!Utils.isNullOrEmpty(embeddedVP)) {
                            if (Utils.isNullOrEmpty(expVP)) {
                                prefix = embeddedVP;
                            } else {
                                prefix = expVP + embeddedVP;
                            }
                        }
                        blob = container.getBlockBlobReference(prefix + src.getName());
                    }

                    long startTime = System.currentTimeMillis();
                    InputStream inputStream = src.read();
                    try {
                        blob.upload(inputStream, src.length(), null, getBlobRequestOptions(), null);
                    } finally {
                        try {
                            inputStream.close();
                        } catch (IOException e) {

                        }
                    }
                    long endTime = System.currentTimeMillis();
                    listener.getLogger().println(
                            "Uploaded blob with uri " + blob.getUri() + " in " + getTime(endTime - startTime));
                    blobs.add(new CloudBlob(blob.getName(),
                            blob.getUri().toString().replace("http://", "https://")));
                    filesUploaded++;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new WAStorageException(e.getMessage(), e.getCause());
    }
    return filesUploaded;
}

From source file:com.reactive.hzdfs.TestRunner.java

@Test
public void testFailOnZIPFile() {
    Throwable c = null;/*w w  w  .  j av a 2  s . co m*/

    try {
        File f = ResourceLoaderHelper.loadFromFileOrClassPath("text_example.zip");
        Future<DFSSResponse> fut = dfss.distribute(f, new DFSSTaskConfig());
        fut.get();
        Assert.fail();
    } catch (IOException e) {
        Assert.fail("IOException - " + e);
    } catch (InterruptedException e) {
        Assert.fail("InterruptedException - " + e);
    } catch (ExecutionException e) {
        c = e.getCause();

    }
    Assert.assertNotNull(c);
    Assert.assertTrue(c instanceof DFSSException);
    Assert.assertEquals(DFSSException.ERR_IO_FILE, ((DFSSException) c).getErrorCode());
}

From source file:com.reactive.hzdfs.TestRunner.java

@Test
public void testFailOnPPTFile() {
    Throwable c = null;//from   ww  w.j av  a2 s  . c o  m

    try {
        File f = ResourceLoaderHelper.loadFromFileOrClassPath("Presentation1.pptx");
        Future<DFSSResponse> fut = dfss.distribute(f, new DFSSTaskConfig());
        fut.get();
        Assert.fail();
    } catch (IOException e) {
        Assert.fail("IOException - " + e);
    } catch (InterruptedException e) {
        Assert.fail("InterruptedException - " + e);
    } catch (ExecutionException e) {
        c = e.getCause();

    }
    Assert.assertNotNull(c);
    Assert.assertTrue(c instanceof DFSSException);
    Assert.assertEquals(DFSSException.ERR_IO_FILE, ((DFSSException) c).getErrorCode());
}

From source file:com.appcel.core.encoder.executor.FfmpegEncoderExecutor.java

/**
 * Executes the ffmpeg process with the previous given arguments.
 * //  www  . j a v  a 2 s. c  o  m
 * @throws IOException
 *             If the process call fails.
 */
public void execute(File directory) throws EncoderException {

    LOGGER.info("==========>>>  ffmpeg ?...");
    try {
        int argsSize = args.size();
        String[] cmd = new String[argsSize + 1];
        cmd[0] = executablePath;
        for (int i = 0; i < argsSize; i++) {
            cmd[i + 1] = args.get(i);
        }

        LOGGER.info("Ffmpeg  ===>>> " + args);

        Runtime runtime = Runtime.getRuntime();

        ffmpeg = runtime.exec(cmd, null, directory);

        ffmpegKiller = new ProcessKiller(ffmpeg);
        runtime.addShutdownHook(ffmpegKiller);
        inputStream = ffmpeg.getInputStream();
        outputStream = ffmpeg.getOutputStream();
        errorStream = ffmpeg.getErrorStream();

        LOGGER.info("==========>>> ffmpeg ??.");
    } catch (IOException e) {
        LOGGER.error("==========>>> ffmpeg ? Message: " + e.getMessage());
        LOGGER.error("==========>>> ffmpeg ? Cause: " + e.getCause());
        e.printStackTrace();
    } finally {
        destroy();
    }
}