Example usage for java.io IOException fillInStackTrace

List of usage examples for java.io IOException fillInStackTrace

Introduction

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

Prototype

public synchronized Throwable fillInStackTrace() 

Source Link

Document

Fills in the execution stack trace.

Usage

From source file:uk.nhs.cfh.dsp.srth.query.converters.file.impl.QueryExpressionFileOutputterImpl.java

/**
 * Save to file.//from   w w w . j a  va 2s.co  m
 *
 * @param file the file
 * @param element the element
 */
private void saveToFile(File file, Element element) {
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    Writer writer;
    try {
        writer = new FileWriter(file);
        outputter.output(element, writer);
    } catch (IOException e) {
        logger.warn("Error saving query to file. Nested exception is : " + e.fillInStackTrace().getMessage());
    }
}

From source file:org.mule.module.launcher.ArtifactArchiveInstaller.java

/**
 * Installs an artifact in the mule container.
 *
 * Created the artifact directory and the anchor file related.
 *
 * @param artifactUrl URL of the artifact to install. It must be present in the artifact directory as a zip file.
 * @return the name of the installed artifact.
 * @throws IOException in case there was an error reading from the artifact or writing to the artifact folder.
 *///  w  w w  .  j a va 2s . c  o  m
public String installArtifact(final URL artifactUrl) throws IOException {
    if (!artifactUrl.toString().endsWith(".zip")) {
        throw new IllegalArgumentException("Invalid Mule artifact archive: " + artifactUrl);
    }

    final String baseName = FilenameUtils.getBaseName(artifactUrl.toString());
    if (baseName.contains("%20")) {
        throw new DeploymentInitException(
                MessageFactory.createStaticMessage("Mule artifact name may not contain spaces: " + baseName));
    }

    File artifactDir = null;
    boolean errorEncountered = false;
    String artifactName;
    try {
        final String fullPath = artifactUrl.toURI().toString();

        if (logger.isInfoEnabled()) {
            logger.info("Exploding a Mule artifact archive: " + fullPath);
        }

        artifactName = FilenameUtils.getBaseName(fullPath);
        artifactDir = new File(artifactParentDir, artifactName);
        // normalize the full path + protocol to make unzip happy
        final File source = new File(artifactUrl.toURI());

        FileUtils.unzip(source, artifactDir);
        if ("file".equals(artifactUrl.getProtocol())) {
            FileUtils.deleteQuietly(source);
        }
    } catch (URISyntaxException e) {
        errorEncountered = true;
        final IOException ex = new IOException(e.getMessage());
        ex.fillInStackTrace();
        throw ex;
    } catch (IOException e) {
        errorEncountered = true;
        throw e;
    } catch (Throwable t) {
        errorEncountered = true;
        final String msg = "Failed to install artifact from URL: " + artifactUrl;
        throw new DeploymentInitException(MessageFactory.createStaticMessage(msg), t);
    } finally {
        // delete an artifact dir, as it's broken
        if (errorEncountered && artifactDir != null && artifactDir.exists()) {
            FileUtils.deleteTree(artifactDir);
        }
    }
    return artifactName;
}

From source file:uk.nhs.cfh.dsp.srth.query.converters.file.impl.QueryExpressionFileOutputterImpl.java

/**
 * Save./*from   ww w. j av  a 2  s.  c  o m*/
 *
 * @param queryStatement the query statement
 * @param physicalURI the physical uri
 */
public void save(QueryStatement queryStatement, URI physicalURI) {

    if (logger.isDebugEnabled()) {
        logger.debug("Saving query to physicalURI = " + physicalURI);
    }
    // get file location for URL
    File file = new File(physicalURI);
    if (!file.exists()) {
        try {
            boolean success = file.createNewFile();
            if (success) {
                // save to file as XML
                saveToFile(file, queryExpressionXMLConverter.getElementForQueryStatement(queryStatement));
            }

        } catch (IOException e) {
            logger.warn(
                    "Error writing query to file. Nested exception is : " + e.fillInStackTrace().getMessage());
        }
    } else {
        // save to file as XML
        saveToFile(file, queryExpressionXMLConverter.getElementForQueryStatement(queryStatement));

    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.queryresultspanel.actions.ExportResultTask.java

@Override
protected Void doInBackground() throws Exception {

    // open file dialog to get save location
    FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(),
            "Select location to save", FileDialog.SAVE);
    fd.setVisible(true);/*from  w w w  .j  ava 2 s .com*/

    String selectedFile = fd.getFile();
    String selectedDirectory = fd.getDirectory();
    if (selectedDirectory != null && selectedFile != null && resultSet != null) {
        try {
            // save to selected location
            File file = new File(selectedDirectory, selectedFile);
            // export to flat file
            FileWriter fw = new FileWriter(file);
            fw.flush();

            // add column names to data
            String cols = "";
            int colNum = resultSet.getMetaData().getColumnCount();
            for (int c = 0; c < colNum; c++) {
                cols = cols + "\t" + resultSet.getMetaData().getColumnName(c + 1);
            }

            // trim line and add new line character
            cols = cols.trim();
            cols = cols + "\n";
            // write to file
            fw.write(cols);

            float totalRows = resultSetCount;
            float percent = 0;
            int counter = 0;

            // reset resultSet to first row in case its been iterated over before
            resultSet.beforeFirst();
            while (resultSet.next()) {
                String line = "";
                for (int l = 0; l < colNum; l++) {
                    Object o = resultSet.getObject(l + 1);
                    if (o instanceof Date) {
                        o = sdf.format((Date) o);
                    } else if (o instanceof byte[]) {
                        byte[] bytes = (byte[]) o;
                        o = UUID.nameUUIDFromBytes(bytes).toString();
                    }

                    line = line + "\t" + o.toString();
                }

                // trim line
                line = line.trim();
                // append new line character to line
                line = line + "\n";
                // write to file
                fw.write(line);

                // update progress bar
                percent = (counter / totalRows) * 100;
                setProgress((int) percent);
                setMessage("Exported " + counter + " of " + totalRows + " rows");

                counter++;
            }

            // close file writer
            fw.close();

        } catch (IOException e) {
            logger.warn("Nested exception is : " + e.fillInStackTrace());
        }
    }

    return null;
}

From source file:org.mule.module.launcher.DefaultMuleDeployer.java

public Application installFrom(URL url) throws IOException {
    if (applicationFactory == null) {
        throw new IllegalStateException("There is no application factory");
    }//from  w w w .j ava2 s.c  o  m

    // TODO plug in app-bloodhound/validator here?
    if (!url.toString().endsWith(".zip")) {
        throw new IllegalArgumentException("Invalid Mule application archive: " + url);
    }

    final String baseName = FilenameUtils.getBaseName(url.toString());
    if (baseName.contains("%20")) {
        throw new DeploymentInitException(MessageFactory
                .createStaticMessage("Mule application name may not contain spaces: " + baseName));
    }

    String appName;
    File appDir = null;
    boolean errorEncountered = false;
    try {
        final File appsDir = MuleContainerBootstrapUtils.getMuleAppsDir();

        final String fullPath = url.toURI().toString();

        if (logger.isInfoEnabled()) {
            logger.info("Exploding a Mule application archive: " + fullPath);
        }

        appName = FilenameUtils.getBaseName(fullPath);
        appDir = new File(appsDir, appName);
        // normalize the full path + protocol to make unzip happy
        final File source = new File(url.toURI());

        FileUtils.unzip(source, appDir);
        if ("file".equals(url.getProtocol())) {
            FileUtils.deleteQuietly(source);
        }
    } catch (URISyntaxException e) {
        errorEncountered = true;
        final IOException ex = new IOException(e.getMessage());
        ex.fillInStackTrace();
        throw ex;
    } catch (IOException e) {
        errorEncountered = true;
        // re-throw
        throw e;
    } catch (Throwable t) {
        errorEncountered = true;
        final String msg = "Failed to install app from URL: " + url;
        throw new DeploymentInitException(MessageFactory.createStaticMessage(msg), t);
    } finally {
        // delete an app dir, as it's broken
        if (errorEncountered && appDir != null && appDir.exists()) {
            final boolean couldNotDelete = FileUtils.deleteTree(appDir);
            /*
            if (couldNotDelete)
            {
            final String msg = String.format("Couldn't delete app directory '%s' after it failed to install", appDir);
            logger.error(msg);
            }
            */
        }
    }

    // appname is never null by now
    return applicationFactory.createApp(appName);
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.app.impl.ModularDockingApplication.java

private void setApplicationProperties(String propertiesFileLocation) {
    Properties properties = new Properties();
    if (propertiesFileLocation != null) {
        try {//ww  w.  j a v  a  2 s.co  m
            properties.load(new FileReader(propertiesFileLocation));
            while (applicationService == null || applicationService.getApplicationProperties() == null) {
                // set properties
                if (applicationService != null) {
                    applicationService.setApplicationProperties(properties);
                }
            }
        } catch (IOException e) {
            logger.warn("Error load properties from file specified. " + "Nested exception is : "
                    + e.fillInStackTrace());
        }
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.app.impl.ModularApplicationAboutDialog.java

/**
 * Creates the buttons panel./* w  w w .  j  av  a 2  s  .  c  o  m*/
 */
private void createButtonsPanel() {

    JideButton aboutButton = new JideButton(new AbstractAction("About") {

        public void actionPerformed(ActionEvent arg0) {
            // show features in info panel
            infoPane.setText(createHTMLText());
        }
    });

    JideButton featuresButton = new JideButton(new AbstractAction("Features") {

        public void actionPerformed(ActionEvent arg0) {
            // show features in info panel
            if (featuresHtmlURL == null) {
                featuresHtmlURL = ModularApplicationAboutDialog.class.getResource("resources/features.html");
            }

            try {
                infoPane.setEditorKit(new HTMLEditorKit());
                infoPane.setPage(featuresHtmlURL);
            } catch (IOException e) {
                logger.warn("Nested exception is : " + e.fillInStackTrace());
            }
        }
    });

    JButton libsButton = new JideButton(new AbstractAction("Libraries") {

        public void actionPerformed(ActionEvent arg0) {
            // show dependencies in info panel
            if (dependenciesHtmlURL == null) {
                dependenciesHtmlURL = ModularApplicationAboutDialog.class
                        .getResource("resources/dependencies.html");
            }

            try {
                infoPane.setEditorKit(new HTMLEditorKit());
                infoPane.setPage(dependenciesHtmlURL);
            } catch (IOException e) {
                logger.warn("Nested exception is : " + e.fillInStackTrace());
            }
        }
    });

    JButton closeButton = new JButton(new AbstractAction("Close") {

        public void actionPerformed(ActionEvent arg0) {
            setVisible(false);
        }
    });

    JPanel buttonsPanel = new JPanel(new GridLayout(1, 0));
    buttonsPanel.add(aboutButton);
    buttonsPanel.add(featuresButton);
    buttonsPanel.add(libsButton);
    buttonsPanel.add(closeButton);
    mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.app.impl.ModularApplicationAboutDialog.java

public void setPropertiesFileLocation(String propertiesFilePath) throws MalformedURLException {

    this.propertiesFilePath = propertiesFilePath;

    File propsFile = new File(propertiesFilePath);
    Properties props = new Properties();
    if (propsFile.exists() && propsFile.canRead()) {
        try {//from   ww  w .  java  2 s . co m
            props.load(new FileInputStream(propsFile));
        } catch (IOException e) {
            logger.warn("Error reading properties file. Nested exception is : " + e.fillInStackTrace());
        }
    }

    if (props.keySet().size() < 1) {
        appTitle = resourceMap.getString("Application.title");
        appDesc = resourceMap.getString("Application.description");
        appVersionMajor = resourceMap.getString("Application.version.major");
        buildId = resourceMap.getString("Application.build.id");
        buildNumber = resourceMap.getString("Application.build.no");
        authorName = resourceMap.getString("Application.author");
        authorContact = resourceMap.getString("Application.author.contact");
        vendor = resourceMap.getString("Application.vendor");
    } else {
        appTitle = props.getProperty("Application.title");
        appDesc = props.getProperty("Application.description");
        appVersionMajor = props.getProperty("Application.version.major");
        buildId = props.getProperty("Application.build.id");
        buildNumber = props.getProperty("Application.build.no");
        authorName = props.getProperty("Application.author");
        authorContact = props.getProperty("Application.author.contact");
        vendor = props.getProperty("Application.vendor");
        File dependenciesHTMLFile = new File(props.getProperty("application.features.html.path"));
        dependenciesHtmlURL = dependenciesHTMLFile.toURI().toURL();
        File featuresHTMLFile = new File(props.getProperty("application.dependencies.html.path"));
        featuresHtmlURL = featuresHTMLFile.toURI().toURL();
    }
}

From source file:uk.nhs.cfh.dsp.srth.distribution.FileDownloader.java

public FileDownloader(FTPClient ftpClient) {

    this.ftpClient = ftpClient;
    try {//from w  w  w.  ja  v a 2  s  . c om
        logger.addHandler(
                new FileHandler(System.getProperty("java.io.tmpdir") + SEPARATOR + "configurator.log", true));
    } catch (IOException e) {
        logger.warning(ERR_MESSAGE + e.fillInStackTrace().getMessage());
    }
}

From source file:uk.nhs.cfh.dsp.yasb.indexgenerator.SnomedLuceneDescriptionIndexer.java

/**
 * Instantiates a new snomed lucene description indexer.
 *
 * @param dataSource the data source/*from  ww w  . j  a  va 2  s.  com*/
 * @param terminologyConceptDAO the terminology concept dao
 */
public SnomedLuceneDescriptionIndexer(DataSource dataSource, TerminologyConceptDAO terminologyConceptDAO) {

    try {
        this.connection = dataSource.getConnection();
        this.terminologyConceptDAO = terminologyConceptDAO;

        // create directory;
        try {
            directory = FSDirectory.getDirectory(System.getProperty("user.dir") + "/index/snomed-desc/lucene");
            logger.debug("Value of directory : " + directory);
            indexWriter = new IndexWriter(directory, new StandardAnalyzer(), true,
                    IndexWriter.MaxFieldLength.UNLIMITED);

        } catch (IOException e) {
            logger.warn("Error locating location of index directory.\n" + "Nested exception is : "
                    + e.fillInStackTrace());
        }
    } catch (SQLException e) {
        logger.warn("Error obtaining connection from data source.\n" + "Nested exception is : "
                + e.fillInStackTrace());
    }
}