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.yasb.indexgenerator.SnomedLuceneIndexer.java

/**
 * Instantiates a new snomed lucene indexer.
 *
 * @param dataSource the data source// ww w .  j a v a 2  s. c o  m
 * @param terminologyConceptDAO the terminology concept dao
 */
public SnomedLuceneIndexer(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());
    }
}

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

@Override
public String touch(String path, String name) throws IOException {
    initializeIfNecessary();//from   ww  w .  ja  va 2 s.  c  om
    if (mLiveConnectClient == null) {
        return null;
    }

    File temp = File.createTempFile("document", null, mContext.getCacheDir());
    if (!temp.exists()) {
        IOException ioException = new IOException("Failed to touch " + name);
        ioException.fillInStackTrace();
        throw ioException;
    }
    return upload(path, name, temp);
}

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

@Override
public String upload(String path, String name, File file) throws IOException {
    initializeIfNecessary();//from  www  . j av a2 s .  c  om
    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();//from  www. java  2  s .c  om
    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:uk.nhs.cfh.dsp.srth.distribution.FileDownloader.java

private void extractZipFileContents(File file) {
    Enumeration entries;//from w w  w. j a  va  2s  .  c o  m

    try {
        logger.info("Extracting zip file contents...");
        ZipFile zipFile = new ZipFile(file);

        entries = zipFile.getEntries();

        while (entries.hasMoreElements()) {
            ZipArchiveEntry entry = (ZipArchiveEntry) entries.nextElement();

            if (entry.isDirectory()) {

                logger.info("Extracting directory: " + entry.getName());
                File dir = new File(file.getParent(), entry.getName());
                boolean canWrite = dir.exists();
                if (!canWrite) {
                    canWrite = dir.mkdir();
                }

                if (canWrite) {
                    continue;
                } else {
                    logger.warning("Error creating directory during extraction");
                }
            }

            logger.info("Extracting file: " + entry.getName());
            copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(
                    new FileOutputStream(new File(file.getParent(), entry.getName()))));
        }

        zipFile.close();
        logger.info("Closed zip file.");
    } catch (IOException e) {
        logger.warning("Nested exception is : " + e.fillInStackTrace());
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.resultexplanationpanel.QueryStatisticsCollectionPanel.java

/**
 * Creates the statements panel./*from   w w  w.  j  ava  2  s  . com*/
 * 
 * @param textArea the text area
 * @param title the title
 * 
 * @return the j panel
 */
private synchronized JPanel createStatementsPanel(final JTextArea textArea, String title) {

    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(),
            BorderFactory.createTitledBorder(title)));

    // create buttons for copy and export
    JButton copyButton = new JButton(new AbstractAction("Copy") {

        public void actionPerformed(ActionEvent event) {
            StringSelection selection = new StringSelection(textArea.getSelectedText());
            // get contents of text area and copy to system clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(selection, QueryStatisticsCollectionPanel.this);
        }
    });

    JButton exportButton = new JButton(new AbstractAction("Export") {

        public void actionPerformed(ActionEvent event) {
            // open a file dialog and export the contents
            FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(),
                    "Select file to export to", FileDialog.SAVE);
            fd.setVisible(true);

            String fileName = fd.getFile();
            String fileDirectory = fd.getDirectory();

            if (fileDirectory != null && fileName != null) {
                File file = new File(fileDirectory, fileName);
                try {
                    String contents = textArea.getText();
                    FileWriter fw = new FileWriter(file);
                    fw.flush();
                    fw.write(contents);
                    fw.close();
                    // inform user
                    //                  manager.getStatusMessageLabel().setText("Successfully saved contents to file "+fileName);
                    logger.info("Successfully saved contents to file " + fileName);

                } catch (IOException e) {
                    logger.warn(e.fillInStackTrace());
                    //                  manager.getStatusMessageLabel().setText("Errors saving contents to file "+fileName);
                }
            }
        }
    });
    // create buttons panel
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS));
    buttonsPanel.add(Box.createHorizontalStrut(200));
    buttonsPanel.add(copyButton);
    buttonsPanel.add(exportButton);

    panel.add(buttonsPanel, BorderLayout.SOUTH);
    panel.add(new JScrollPane(textArea), BorderLayout.CENTER);

    return panel;
}

From source file:uk.nhs.cfh.dsp.yasb.search.impl.SNOMEDCTSearchServiceProvider.java

/**
 * A synchronised method that sets up the index!.
 *//*from   ww w .  j av  a2 s .  c om*/
private synchronized void setupIndex() {
    try {
        Directory directory = FSDirectory.getDirectory(new File(getIndexLocation()));
        // set up index searcher
        indexSearcher = new IndexSearcher(directory);
    } catch (IOException e) {
        logger.warn("Error locating search index. Nested exception is : " + e.fillInStackTrace());
    }
}

From source file:org.opens.tanaguru.util.http.HttpRequestHandler.java

public int getHttpStatus(String url) {
    String encodedUrl = getEncodedUrl(url);
    HttpClient httpClient = getHttpClient(encodedUrl);
    HeadMethod head = new HeadMethod(encodedUrl);
    try {/*from ww w .  ja  v  a 2s .c o  m*/
        LOGGER.debug("executing head request to retrieve page status on " + head.getURI());
        int status = httpClient.executeMethod(head);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("received " + status + " from head request");
            for (Header h : head.getResponseHeaders()) {
                LOGGER.debug("header : " + h.toExternalForm());
            }
        }

        return status;
    } catch (UnknownHostException uhe) {
        LOGGER.warn("UnknownHostException on " + encodedUrl);
        return HttpStatus.SC_NOT_FOUND;
    } catch (IllegalArgumentException iae) {
        LOGGER.warn("IllegalArgumentException on " + encodedUrl);
        return HttpStatus.SC_NOT_FOUND;
    } catch (IOException ioe) {
        LOGGER.warn("IOException on " + encodedUrl);
        ioe.fillInStackTrace();
        return HttpStatus.SC_NOT_FOUND;
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        head.releaseConnection();
    }
}

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

public void getFileFromTRUD(String fileName, String outputURL) {

    logger.info("Now getting file... ");
    if (ftpClient.isConnected()) {
        // now get file specified by inputURL
        try {//from w  ww.j av  a  2 s. c o m
            // send NOOP command to see if connection is still active
            if (ftpClient.sendNoOp()) {
                logger.info("Now listing directory... ");
                FTPFile[] files = ftpClient.listFiles(getPackPath());
                for (FTPFile file : files) {
                    logger.info("file.getName() = " + file.getName());
                    logger.info("file.getSize() = " + file.getSize());
                    if (file.getName().equals(fileName) && file.getSize() > 0) {
                        InputStream is = ftpClient.retrieveFileStream(getPackPath() + fileName);
                        if (is != null) {
                            getFileFromStream(is, outputURL);
                        }
                        break;
                    }
                }
            } else {
                ftpClient.disconnect();
                checkAndOpenFTPConnection();
            }
        } catch (IOException e) {
            logger.warning(
                    "FTP connection might have timed out. Nested exception is : " + e.fillInStackTrace());
        }
    } else {
        logger.warning("No connection to TRUD is available. Ensure FTP connection is open");
    }
}

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

public void getFileFromTRUDArchive(String trudArchiveName, String fileName, String outputURL) {

    logger.info("Now getting file... ");
    if (ftpClient.isConnected()) {
        logger.info("ftp client is connected... ");
        // now get file specified by inputURL
        try {//  w ww.j a v a 2s. com
            ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
            logger.info("Sending NOOP command... ");
            // send NOOP command to see if connection is still active
            if (ftpClient.sendNoOp()) {
                logger.info("ftpClient.getReplyString() = " + ftpClient.getReplyString());
                FTPFile[] files = ftpClient.listFiles(getPackPath());
                for (FTPFile file : files) {
                    logger.info("file.getName() = " + file.getName());
                    logger.info("file.getSize() = " + file.getSize());
                    if (file.getName().equals(trudArchiveName) && file.getSize() > 0) {
                        InputStream is = ftpClient.retrieveFileStream(getPackPath() + trudArchiveName);

                        if (is != null) {
                            ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(is);
                            ZipArchiveEntry zipArchiveEntry = zipArchiveInputStream.getNextZipEntry();
                            while (zipArchiveEntry != null) {
                                String zippedArchiveEntryName = zipArchiveEntry.getName();
                                logger.info("zippedArchiveEntryName = " + zippedArchiveEntryName);
                                logger.info("fileName = " + fileName);
                                if (zippedArchiveEntryName.equals(fileName)) {
                                    logger.info("Extracting: " + zippedArchiveEntryName);
                                    File outputLocation = new File(outputURL);
                                    boolean canWrite = outputLocation.exists();
                                    logger.info("canWrite = " + canWrite);
                                    if (!canWrite) {
                                        canWrite = outputLocation.mkdirs();
                                        logger.info("canWrite after mkdirs = " + canWrite);
                                    }

                                    if (canWrite && outputLocation.canWrite()) {
                                        logger.info("outputLocation.getPath() = " + outputLocation.getPath());
                                        File destinationFile = new File(outputLocation.getAbsolutePath(),
                                                zippedArchiveEntryName);
                                        OutputStream out = new FileOutputStream(destinationFile);
                                        IOUtils.copy(zipArchiveInputStream, out);
                                        out.close();

                                        if (zippedArchiveEntryName.indexOf(".zip") > -1) {
                                            // unpackZip file
                                            extractZipFileContents(destinationFile);
                                        }
                                    }
                                } else {
                                    logger.info("Resetting zipArchiveEntry");
                                    zipArchiveEntry = zipArchiveInputStream.getNextZipEntry();
                                    if (zipArchiveEntry != null) {
                                        logger.info("zipArchiveEntry.getName() = " + zipArchiveEntry.getName());
                                    }
                                }

                            }

                            zipArchiveInputStream.close();
                            is.close();
                        }
                        break;
                    }
                }

                // complete pending commands; needed after opening and closing streams
                ftpClient.completePendingCommand();
            } else {
                logger.warning("FTP connection might have timed out.");
                ftpClient.disconnect();
            }
        } catch (IOException e) {
            logger.warning("FTP connection might have timed out. " + ERR_MESSAGE + e.fillInStackTrace());
        }
    } else {
        logger.warning("No connection to TRUD is available. Ensure FTP connection is open");
    }
}