Example usage for java.io FileNotFoundException getMessage

List of usage examples for java.io FileNotFoundException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.universal.storage.UniversalFileStorage.java

/**
 * This method retrieves a file from the storage as InputStream.
 * The method will retrieve the file according to the passed path.  
 * A file will be stored within the settings' tmp folder.
 * /*from  w  w  w  .  j a  v  a  2 s  .com*/
 * @param path in context.
 * @returns an InputStream pointing to the retrieved file.
 */
public InputStream retrieveFileAsStream(String path) throws UniversalIOException {
    try {
        return new FileInputStream(retrieveFile(path));
    } catch (FileNotFoundException e) {
        UniversalIOException error = new UniversalIOException(e.getMessage());
        this.triggerOnErrorListeners(error);
        throw error;
    }
}

From source file:com.plugins.pomfromjar.mojo.JarDependencyGenerator.java

/**
 * Writes the depenendecy to a pom file & increments logging counters
 * @param fileName //from   ww w .j a  va2s . com
 * 
 * @param groupId
 * @param artifactId
 * @param version
 * @throws IOException
 */
private void writeDependencyToFile(String fileName) {

    try {

        for (JarFileDependency jarFileDependency : dependencyList.getDistinctDependenciesList()) {
            model.addDependency(jarFileDependency);
        }

        OutputStream fileOutputStream = new FileOutputStream(this.pomFile);
        Writer writer = new BufferedWriter(new OutputStreamWriter(fileOutputStream, "UTF-8"));
        MavenXpp3Writer mavenXpp3Writer = new MavenXpp3Writer();
        mavenXpp3Writer.write(writer, model);
    } catch (FileNotFoundException e) {
        LOGGER.error(
                "********* Exception thrown in JarDependencyGeneratorecreateDependenciesFromJarDir.writeDependencyToFile ********* : "
                        + e.getMessage());
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        LOGGER.error(
                "********* Exception thrown in JarDependencyGeneratorecreateDependenciesFromJarDir.writeDependencyToFile ********* : "
                        + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        LOGGER.error(
                "********* Exception thrown in JarDependencyGeneratorecreateDependenciesFromJarDir.writeDependencyToFile ********* : "
                        + e.getMessage());
        e.printStackTrace();
    }

}

From source file:com.sugarcrm.candybean.configuration.Configuration.java

public void load(File file) throws IOException {
    try {// w  ww . ja  v  a 2 s. co m
        if (file == null) {
            throw new FileNotFoundException("Given file is null.");
        } else {
            this.load(new FileInputStream(file));
        }
    } catch (FileNotFoundException e) {
        // get file name using substring of adjustedPath that starts after the last /
        logger.severe(e.getMessage());
    } catch (IOException e) {
        logger.warning("Unable to load " + file.getCanonicalPath() + ".\n");
        logger.severe(e.getMessage());
    } catch (NullPointerException e) {
        logger.warning("File path is null.\n");
        logger.severe(e.getMessage());
    }

}

From source file:com.carlstahmer.estc.recordimport.daemon.Conf.java

/**
 * <p>An initialization class that tells the object to read the .yml configuration file
 * and load all values.  Must be called before trying to access any class properties.</p>
 * //from www .  j  a v  a2 s .  c  o  m
 * @return               a boolean value indicating whether the configuration .yml has been successfully loaded.
 */
public boolean loadConf() {

    boolean loaded = false;
    // Load Configuration YAML
    try {

        InputStream yamlInput = new FileInputStream(new File("config.yml"));
        System.out.println("Found configuration file...");
        Yaml yaml = new Yaml();
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) yaml.load(yamlInput);
        listenDir = (String) map.get("listendir");
        writeDir = (String) map.get("writedir");
        runInterval = (Integer) map.get("runinterval");
        orgcode = (String) map.get("orgcode");
        dbserver = (String) map.get("dbserver");
        dbname = (String) map.get("dbname");
        dbuser = (String) map.get("dbuser");
        dbpass = (String) map.get("dbpass");
        String tempLangscope = (String) map.get("langscope");
        if (tempLangscope.length() > 0) {
            langscope = tempLangscope;
        }
        if (langscope.length() > 0) {
            setLangCodes();
        }
        int liberalvalue = (Integer) map.get("liberal");
        if (liberalvalue == 1) {
            liberal = true;
        }
        estcCodesCSV = (String) map.get("estccodes");
        estcCodes = estcCodesCSV.split("\\s*,\\s*");

        loaded = true;

    } catch (FileNotFoundException e) {
        System.err.println("Configuration FileNotFoundException: " + e.getMessage());
        loaded = false;
    }

    return loaded;
}

From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.CsvTable.java

public void load(File file) {
    try {//from   w w  w . j a v  a 2  s .  c  o  m
        load(new FileInputStream(file));
    } catch (FileNotFoundException e) {
        throw new RuntimeException(
                "CsvTable; File cannot found: " + file.getAbsolutePath() + "; " + e.getMessage(), e);
    }
}

From source file:edu.odu.cs.cs350.yellow1.jar.ExecuteJar.java

/**
 * /*from   w  ww  .j  av a 2  s  . c o  m*/
 * {@inheritDoc}
 * <br>Run all tests in the test suit on the mutant 
 * capturing the output created and if the execution of the mutant with a test exits successfully compare the standard output generated by<br>
 * the mutant if different stop running tests and return {@link ExecutionResults}
 * <br> Treats exiting the jvm with error as was not killed continue to run more tests 
 * @return {@link ExecutionResults}
 */
@Override
public ExecutionResults call() throws Exception {
    //create new Executor for monitoring mutation running
    executor = new DefaultExecutor();
    //get a MessageDigest Instance for use in comparing outputs
    MessageDigest mDigest = MessageDigest.getInstance("MD5");
    //get file object for gold file
    File f = new File(pathToGold);
    //get the hash value for the gold file
    goldHash = mDigest.digest(FileUtils.readFileToByteArray(f));
    //reset the MessageDigest
    mDigest.reset();
    int testCount = 0;
    //Create a new ExecuteWatchdog with timeout at 10 seconds
    wDog = new ExecuteWatchdog(10000);
    executor.setWatchdog(wDog);
    //loop through the tests till empty
    while (!tests.isEmpty()) {
        //get the next test
        File test = tests.poll();//poll removes the test from the queue
        //prepair captured output files
        String testName = test.getName();
        testName = testName.toUpperCase(Locale.getDefault()).substring(0, testName.indexOf("."));
        String outName = jarName + "_" + testName + "_out.txt";
        String errOutName = jarName + "_" + testName + "_err.txt";
        //create file objects to be written to 
        File standardOut = new File(pathToOutputDir + File.separator + outName);
        File standardErr = new File(pathToOutputDir + File.separator + errOutName);
        //file streams create the files for me
        try {
            log = new FileOutputStream(standardOut);

            err = new FileOutputStream(standardErr);
        } catch (FileNotFoundException e1) {
            logger.error("log or err file not found for jar " + jarName, e1.getMessage());
        }
        //create new stream handler for each execution
        streamHandler = new PumpStreamHandler(/* standard out */log, /* error out */err);
        executor.setStreamHandler(streamHandler);
        //construct the executable command
        CommandLine args = new CommandLine(pathToJVM);
        args.addArgument("-jar");
        args.addArgument(jar.getAbsolutePath());
        args.addArgument(test.getAbsolutePath());
        //new process destroyer per execution
        ShutDownSpawnedJVMProcess killJVM = new ShutDownSpawnedJVMProcess("java -jar " + jarName, 10000);
        killJVM.setWaitOnShutdown(true);
        executor.setProcessDestroyer(killJVM);
        success = false;

        try {
            streamHandler.start();
            int result = executor.execute(args);
            logger.info(jarName + " Sucess with val=[" + result + "] for test[" + testName + "]");
            success = true;
        } catch (ExecuteException ee) {
            logger.error(jarName + " Execute exception " + ee.getMessage() + " with val=[" + ee.getExitValue()
                    + "] for test[" + testName + "]");
        } catch (IOException e) {
            logger.error(jarName + " IOExecption " + e.getMessage());

        } finally {
            //PumpStreamHandler does not guarantee the closing of stream 100% so to release the locks held by the filestreams 
            //on the created output files so close manually 
            //if the streamhandler was able to close then this will through exception which we ignore
            try {
                streamHandler.stop();
                //log.flush();
                log.close();
                //err.flush();
                err.close();
            } catch (IOException e) {
                logger.error(e.getMessage());
                //ignore nothing I can do 
            }

        }

        //if the spawned process exited with success value 
        //check the hash of the output file and delete the empty error file
        //if the hash is different the mutant was killed otherwise test more
        //if the spawned process exited with an error value delete empty standard out file and test more
        if (success) {
            ++numOfSucesses;
            standardErr.delete();
            outFiles.add(standardOut);
            if (!Arrays.equals(goldHash, mDigest.digest(FileUtils.readFileToByteArray(standardOut)))) {
                testMore = false;
                logger.debug("Different hashes for jar [" + jarName + "] for test [" + testName + "]");
            } else {
                logger.debug("Same hashes for jar [" + jarName + "] for test [" + testName + "]");
            }
            mDigest.reset();
        } else {
            ++numOfFailurs;
            standardOut.delete();
            errFiles.add(standardErr);
            this.didNotExecute.add(test);
        }
        ++testCount;
        //the mutant was killed so stop testing 
        if (!testMore) {
            testMore = false;
            killed = true;
            testNumKilledME = testCount;
            break;
        }

    }

    jar.delete();
    return new ExecutionResults(numOfSucesses, numOfFailurs, testNumKilledME, jarName, killed, killedMutant,
            outFiles, errFiles);

}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.environment.WindowsFileEnvironmentRepository.java

public void save(String backupFileName, ConfigResponse config, Environment environment) throws PluginException {
    BufferedReader wrapperconfFileReader = null;
    FileOutputStream newWrapperconf = null;

    try {/*from w ww  .ja va2s.  c o m*/
        try {
            wrapperconfFileReader = new BufferedReader(new FileReader(backupFileName));
        } catch (FileNotFoundException e) {
            throw new PluginException(
                    "Unable to save wrapper.conf.  Error parsing existing file.  Cause: " + e.getMessage());
        }

        try {
            newWrapperconf = new FileOutputStream(
                    Metric.decode(config.getValue("installpath")) + "/conf/wrapper.conf");
        } catch (FileNotFoundException e) {
            throw new PluginException(
                    "Unable to save wrapper.conf.  Error writing to existing file.  Cause: " + e.getMessage());
        }

        // write backup file to wrapper.conf, replacing existing JVM_OPTS and JAVA_HOME
        String line;
        try {
            line = wrapperconfFileReader.readLine();
            boolean processedJvmOpts = false;
            boolean processingJvmOpts = false;
            boolean processedJavaHome = false;
            List<String> exsistingJvmOpts = new ArrayList<String>();
            for (; line != null; line = wrapperconfFileReader.readLine()) {
                /**
                 * The two following "if" statements represents an embedded state machine here where it flip flops
                 * between parsing JVM options and having completed that phase.
                 * 
                 * -- Testing for wrapper.java.additional enters a special state tagged "processingJvmOpts". -- When
                 * the last wrapper.java.additional is passed, it exits the state "processingJvmOpts".
                 * 
                 * The if-then checks for this MUST come before any other checks. Otherwise, the state machine gets
                 * mixed up with other line checks, and can cause lines to be dropped.
                 */
                if (line.trim().startsWith("wrapper.java.additional")) {
                    if (!processingJvmOpts) {
                        processingJvmOpts = true;
                    }
                    // add jvm opt to exsistingJvmOpts
                    int pos = line.indexOf("=");
                    if (pos != -1) {
                        exsistingJvmOpts.add(windowsOptsUtil.stripQuotes(line.substring(pos + 1)));
                    }
                } else if (processingJvmOpts) {
                    writeJvmOpts(environment.getJvmOptions(), newWrapperconf, exsistingJvmOpts);
                    processingJvmOpts = false;
                    processedJvmOpts = true;
                }
                /**
                 * The rest of these else-if's represent simple line checks for parsing and involves no special
                 * state machine.
                 */
                else if (line.trim().equals("")) {
                    newWrapperconf.write(line.getBytes());
                    newWrapperconf.write("\n".getBytes());
                } else if (line.trim().startsWith("set.JAVA_HOME")
                        || line.trim().startsWith("#set.JAVA_HOME")) {
                    if (!processedJavaHome) {
                        writeJavaHome(environment.getJavaHome(), newWrapperconf);
                        processedJavaHome = true;
                    }
                } else {
                    newWrapperconf.write(line.getBytes());
                    newWrapperconf.write("\n".getBytes());
                }
            }
            if (!processedJvmOpts) {
                writeJvmOpts(environment.getJvmOptions(), newWrapperconf, null);
            }
            if (!processedJavaHome) {
                writeJavaHome(environment.getJavaHome(), newWrapperconf);
            }

            newWrapperconf.flush();
            newWrapperconf.getFD().sync();

        } catch (IOException e) {
            throw new PluginException("Error writing JVM options to wrapper.conf.  Cause: " + e.getMessage());
        }
    } finally {
        try {
            if (wrapperconfFileReader != null) {
                wrapperconfFileReader.close();
            }
        } catch (IOException e) {
            logger.warn("Error closing input stream to backup wrapper.conf file.  Cause: " + e.getMessage());
        }
        try {
            if (newWrapperconf != null) {
                newWrapperconf.close();
            }
        } catch (IOException e) {
            logger.warn("Error closing output stream to wrapper.conf file.  Cause: " + e.getMessage());
        }
    }
}

From source file:com.netthreads.mavenize.Pommel.java

/**
 * Read in pom pointed to by path./*from  w w w .  j av a2  s.  com*/
 * 
 * @param pomPath
 * 
 * @return The loaded pom model.
 * 
 * @throws Exception 
 */
private Model readPom(String path) throws PommelException {
    Model model = null;

    InputStream inputStream;
    try {
        inputStream = new FileInputStream(path);
        model = new MavenXpp3Reader().read(inputStream);
    } catch (FileNotFoundException ex) {
        throw new PommelException(ex.getMessage());
    } catch (IOException ex) {
        throw new PommelException(ex.getMessage());
    } catch (XmlPullParserException ex) {
        throw new PommelException(ex.getMessage());
    }

    return model;
}

From source file:com.aurel.track.exchange.excel.ExcelFieldMatchAction.java

/**
 * Render the field match: first time and after a sheet change
 *//*  w  ww  . java2  s. c  o  m*/
@Override
public String execute() {
    File fileOnDisk = new File(excelMappingsDirectory, fileName);
    workbook = ExcelFieldMatchBL.loadWorkbook(excelMappingsDirectory, fileName);
    if (workbook == null) {
        JSONUtility.encodeJSON(servletResponse,
                JSONUtility.encodeJSONFailure(getText("admin.actions.importExcel.err.noWorkbook")), false);
        fileOnDisk.delete();
        return null;
    }
    if (selectedSheet == null) {
        //first rendering (not submit because of sheet change)
        selectedSheet = Integer.valueOf(0);
    }
    //get the previous field mappings
    Map<String, Integer> columNameToFieldIDMap = null;
    Set<Integer> lastSavedIdentifierFieldIDIsSet = null;
    try {
        FileInputStream fis = new FileInputStream(new File(excelMappingsDirectory, mappingFileName));

        ObjectInputStream objectInputStream = new ObjectInputStream(fis);
        columNameToFieldIDMap = (Map<String, Integer>) objectInputStream.readObject();
        lastSavedIdentifierFieldIDIsSet = (Set<Integer>) objectInputStream.readObject();
        objectInputStream.close();
    } catch (FileNotFoundException e) {
        LOGGER.info("Creating the input stream for mapping failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    } catch (IOException e) {
        LOGGER.warn("Saving the mapping failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    } catch (ClassNotFoundException e) {
        LOGGER.warn("Class not found for  the mapping " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    //get the column index to header names from the excel sheet
    SortedMap<Integer, String> columnIndexToColumNameMap = ExcelFieldMatchBL.getFirstRowHeaders(workbook,
            selectedSheet);

    SortedSet<String> excelColumnNames = new TreeSet<String>();
    excelColumnNames.addAll(columnIndexToColumNameMap.values());
    //prepare the best field matching
    if (columNameToFieldIDMap == null) {
        columNameToFieldIDMap = new HashMap<String, Integer>();
    }
    ExcelFieldMatchBL.prepareBestMatchByLabel(excelColumnNames, columNameToFieldIDMap, locale);
    columnIndexToFieldIDMap = ExcelFieldMatchBL.getColumnIndexToFieldIDMap(columNameToFieldIDMap,
            columnIndexToColumNameMap);
    columnIndexIsIdentifierMap = new HashMap<Integer, Boolean>();
    //the saved identifier columns
    if (lastSavedIdentifierFieldIDIsSet != null && !lastSavedIdentifierFieldIDIsSet.isEmpty()) {
        for (Integer columnIndex : columnIndexToFieldIDMap.keySet()) {
            Integer fieldID = columnIndexToFieldIDMap.get(columnIndex);
            columnIndexIsIdentifierMap.put(columnIndex,
                    new Boolean(lastSavedIdentifierFieldIDIsSet.contains(fieldID)));
        }
    }
    //if issueNo is present it is always identifier (first time it should be preselected and any time when mapped also preselected)
    if (columnIndexToFieldIDMap.values().contains(SystemFields.INTEGER_ISSUENO)) {
        for (Integer columnIndex : columnIndexToFieldIDMap.keySet()) {
            Integer fieldID = columnIndexToFieldIDMap.get(columnIndex);
            if (SystemFields.INTEGER_ISSUENO.equals(fieldID)) {
                columnIndexIsIdentifierMap.put(columnIndex, new Boolean(true));
            }
        }
    }
    List<IntegerStringBean> sheetNames = ExcelFieldMatchBL.loadSheetNames(workbook);
    List<IntegerStringBean> matchableFieldsList = ExcelFieldMatchBL.getFieldConfigs(personID, locale);
    Map<Integer, String> columnIndexNumericToLetter = ExcelFieldMatchBL.getFirstRowNumericToLetter(workbook,
            selectedSheet);
    Set<Integer> possibleIdentifiersSet = ExcelFieldMatchBL.getPossibleIdentifierFields();
    Set<Integer> mandatoryIdentifiersSet = ExcelFieldMatchBL.getMandatoryIdentifierFields();
    JSONUtility.encodeJSON(servletResponse,
            ExcelImportJSON.getExcelFieldMatcherJSON(fileName, selectedSheet, sheetNames, matchableFieldsList,
                    columnIndexToColumNameMap, columnIndexNumericToLetter, columnIndexToFieldIDMap,
                    columnIndexIsIdentifierMap, possibleIdentifiersSet, mandatoryIdentifiersSet),
            false);
    return null;
}

From source file:de.jflex.plugin.maven.JFlexMojo.java

private void parseLexFile(File lexFile) throws MojoFailureException, MojoExecutionException {
    assert lexFile.isAbsolute() : lexFile;

    getLog().debug("Generating Java code from " + lexFile.getName());
    ClassInfo classInfo;//from   ww  w  .  j  a va  2  s. c o  m
    try {
        classInfo = LexSimpleAnalyzer.guessPackageAndClass(lexFile);
    } catch (FileNotFoundException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (IOException e) {
        classInfo = new ClassInfo();
        classInfo.className = LexSimpleAnalyzer.DEFAULT_NAME;
        classInfo.packageName = null; // NOPMD
    }

    checkParameters(lexFile);

    /* set destination directory */
    File generatedFile = new File(outputDirectory, classInfo.getOutputFilename());

    /* Generate only if needs to */
    if (lexFile.lastModified() - generatedFile.lastModified() <= this.staleMillis) {
        getLog().info("  " + generatedFile.getName() + " is up to date.");
        getLog().debug("StaleMillis = " + staleMillis + "ms");
        return;
    }

    /*
     * set options. Very strange that JFlex expects this in a static way.
     */
    Options.setDefaults();
    Options.setDir(generatedFile.getParentFile());
    Options.dump = dump;
    Options.verbose = verbose;
    Options.unused_warning = unusedWarning;
    Options.dot = dot;
    Options.legacy_dot = legacyDot;
    Options.emitInputStreamCtor = inputStreamCtor;
    if (skeleton != null) {
        Options.setSkeleton(skeleton);
    }
    Options.jlex = jlex;

    Options.no_minimize = !minimize; // NOPMD
    Options.no_backup = !backup; // NOPMD
    if ("pack".equals(generationMethod)) {
        /* no-op - there is only one generation method */
    } else {
        throw new MojoExecutionException("Illegal generation method: " + generationMethod);
    }

    try {
        Main.generate(lexFile);
        getLog().info("  generated " + generatedFile);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}