Example usage for java.io FileNotFoundException fillInStackTrace

List of usage examples for java.io FileNotFoundException fillInStackTrace

Introduction

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

Prototype

public synchronized Throwable fillInStackTrace() 

Source Link

Document

Fills in the execution stack trace.

Usage

From source file:com.github.jrialland.ajpclient.AbstractTomcatTest.java

@SuppressWarnings("serial")
protected void addStaticResource(final String mapping, final Path file) {

    if (!Files.isRegularFile(file)) {
        final FileNotFoundException fnf = new FileNotFoundException(file.toString());
        fnf.fillInStackTrace();
        throw new IllegalArgumentException(fnf);
    }/*ww  w .j av a  2  s  . c  o m*/

    String md5;
    try {
        final InputStream is = file.toUri().toURL().openStream();
        md5 = computeMd5(is);
        is.close();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    final String fMd5 = md5;

    addServlet(mapping, new HttpServlet() {
        @Override
        protected void service(final HttpServletRequest req, final HttpServletResponse resp)
                throws ServletException, IOException {
            resp.setContentLength((int) Files.size(file));
            resp.setHeader("Content-MD5", fMd5);
            final String mime = Files.probeContentType(file);
            if (mime != null) {
                resp.setContentType(mime);
            }
            final OutputStream out = resp.getOutputStream();
            Files.copy(file, out);
            out.flush();
        }
    });
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.UserGroupData.java

public void loadStructureMapFileTypes(final boolean throwFileTypesException) throws FileNotFoundException {
    try {/*w  ww  .  j a va2s .  c om*/
        FileTypesSingleton.getFileTypesSingleton(fileTypesPropFile);
    } catch (FileNotFoundException ex) {
        final StringBuffer message = new StringBuffer(200);
        message.append(
                "Error loading the file containing Structure Map File Descriptions.\nPlease make sure the file \"");
        message.append(fileTypesPropFile);
        message.append("\" exists and is of valid format.\nSee the Indigo log for further details.");
        LOG.error(message.toString(), ex);
        if (throwFileTypesException) {
            final FileNotFoundException exNew = new FileNotFoundException(message.toString());
            exNew.fillInStackTrace();
            throw exNew; // NOPMD Stack trace is filled in
        }
    }
}

From source file:uk.nhs.cfh.dsp.snomed.converters.compositionalgrammar.parser.SnomedExpressionParserTest.java

/**
 * Test lex and parse.//from ww  w.  j  av  a  2s  .co  m
 *
 * @throws Exception the exception
 */
public void testLexAndParse() throws Exception {

    // Parse the test file
    String source = testFile.getAbsolutePath();
    try {
        lexer.setCharStream(new ANTLRFileStream(source, "UTF8"));

        // Using the lexer as the token source, we create a token
        // stream to be consumed by the parser
        //
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        assertNotNull("Token passed by lexer must not be null", tokens);

        // Now we need an instance of our parser
        //
        SnomedExpressionParser parser = new SnomedExpressionParser(tokens);
        assertNotNull("Parser must not be null", parser);

        // Provide some user feedback
        //
        logger.info("    Lexer Start");
        long start = System.currentTimeMillis();
        tokens.LT(1);
        long lexerStop = System.currentTimeMillis();
        logger.info("      Lexed in " + (lexerStop - start) + "ms.");

        // And now we merely invoke the start rule for the parser
        //
        logger.info("    Parser Start");
        long pStart = System.currentTimeMillis();
        SnomedExpressionParser.snomed_return parserReturn = parser.snomed();
        assertNotNull("Parser return must not be null null", parserReturn);
        long stop = System.currentTimeMillis();
        logger.info("      Parsed in " + (stop - pStart) + "ms.");

        // Pick up the generic tree
        //
        CommonTree t = (CommonTree) parserReturn.getTree();
        assertNotNull("AST must not be null", t);
        String treeOutput = t.toStringTree();
        assertNotNull("Tree output must not be null", t);
        logger.info("treeOutput = " + treeOutput);

        CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        nodes.setTokenStream(tokens);
        assertNotNull("Node stream must not be null", nodes);

        // NOw walk it with the generic tree walker, which does nothing but
        // verify the tree really.
        //
        try {
            if (parser.getNumberOfSyntaxErrors() == 0) {
                SnomedExpressionTree walker = new SnomedExpressionTree(nodes, testTerminologyDAO);
                assertNotNull("Expression tree must not be null", walker);
                logger.info("    AST Walk Start\n");
                pStart = System.currentTimeMillis();
                AbstractExpressionWithFocusConcepts returnedExpression = walker.expression();
                assertNotNull("Returned expression must not be null", returnedExpression);
                logger.info("returnedExpression = " + returnedExpression);
                stop = System.currentTimeMillis();
                logger.info("\n      AST Walked in " + (stop - pStart) + "ms.");
            }

            // output tree to a graphics file using DOT
            if (tokens.size() < 4096) {
                // Use the ANLTR built in dot generator
                //
                DOTTreeGenerator gen = new DOTTreeGenerator();
                assertNotNull("DOT generator must not be null", gen);
                source = source.substring(0, source.length() - 3);
                String outputName = source + "dot";
                logger.info("    Producing AST dot (graphviz) file");

                StringTemplate st = gen.toDOT(t, new CommonTreeAdaptor());
                assertNotNull("String template must not be null", st);
                // Create the output file and write the dot spec to it
                //
                FileWriter outputStream = new FileWriter(outputName);
                outputStream.write(st.toString());
                outputStream.close();

                //                    // Invoke dot to generate a .png file
                //                    //
                //                    logger.info("    Producing png graphic for tree");
                //                    pStart = System.currentTimeMillis();
                //                    Process proc = Runtime.getRuntime().exec("dot -Tpng -o" + source + "png " + outputName);
                //                    proc.waitFor();
                //                    File dotFile = new File(SnomedExpressionParserTest.class.getResource("test-expression.png").toURI());
                //                    assertTrue("File must exist", dotFile.exists());
                //                    stop = System.currentTimeMillis();
                //                    logger.info("      PNG graphic produced in " + (stop - pStart) + "ms.");
            }
        } catch (Exception e) {
            logger.warn("AST Walk caused an error. Nested exception is : " + e.fillInStackTrace());
        }
    } catch (FileNotFoundException ex) {
        // The file we tried to parse does not exist
        //
        logger.warn("\n  !!The file " + source + " does not exist!!\n");
    } catch (Exception ex) {
        // Something went wrong in the parser, report this
        logger.warn("Parser threw an exception. Nested exception is : " + ex.fillInStackTrace());
    }
}

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

@Action(block = Task.BlockingScope.ACTION, enabledProperty = "workspaceFileEnabled")
public void saveViewLayout() {
    // get persistence delegate and save settings
    try {/*from ww  w .j  a  v a  2s  . com*/
        FileOutputStream output = new FileOutputStream(workspaceFile);
        toolWindowManager.getPersistenceDelegate().save(output);
        output.close();
        statusMessageLabel.setText("Saved workspace layout");
        logger.info("Saved workspace layout");

    } catch (FileNotFoundException e) {
        logger.warn("File not found. Nested exception is : " + e.fillInStackTrace());
    } catch (IOException e) {
        logger.warn("IO exception. Nested exception is : " + e.fillInStackTrace());
    }
}

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

@Action(block = Task.BlockingScope.ACTION, enabledProperty = "workspaceFileEnabled")
public void restoreViewLayout() {
    // restore view layout from file
    try {//w  w w .j a v  a  2  s.  c  o  m
        InputStream is = new FileInputStream(workspaceFile);
        toolWindowManager.getPersistenceDelegate().apply(is);
        is.close();
        statusMessageLabel.setText("Restored workspace layout");
        logger.info("Restored workspace layout");

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

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

public void getFileFromStream(InputStream inputStream, String outputURL) {

    try {// w ww.  ja  v  a2  s .  co m
        FileOutputStream fos = new FileOutputStream(outputURL);
        logger.info("fos = " + fos);
        fos.flush();

        BufferedInputStream in = new BufferedInputStream(inputStream);
        BufferedOutputStream bout = new BufferedOutputStream(fos, BUFFER);
        bout.flush();

        int i = 0;
        byte[] data = new byte[BUFFER];
        // write data
        while ((i = in.read(data, 0, BUFFER)) >= 0) {
            bout.write(data, 0, i);
        }

        // close streams
        bout.close();
        in.close();
        fos.close();

        // log message
        logger.info("Successfully downloaded file to : " + outputURL);
    } catch (FileNotFoundException e) {
        logger.warning(ERR_MESSAGE + e.fillInStackTrace());
    } catch (IOException e) {
        logger.warning(ERR_MESSAGE + e.fillInStackTrace());
    }
}

From source file:uni.bielefeld.cmg.sparkhit.io.TextFileBufferInput.java

/**
 *
 *//*from   ww  w  .j  av a  2s. c  o m*/
private void setFileInputStream() {
    try {
        this.inputFileStream = new FileInputStream(inputPath);
    } catch (FileNotFoundException e) {
        e.fillInStackTrace();
        System.exit(0);
    }
}