Example usage for java.io FileNotFoundException printStackTrace

List of usage examples for java.io FileNotFoundException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.idocbox.common.config.PropertyUtil.java

/**
 * get properties object of given properties file name.
 * @param propertiesFileName//  ww  w . j  a v a  2 s  . co  m
 * @return
 */
public static Properties getProperties(String propertiesFileName) {
    Properties p = null;
    if (null == propertiesFileMap) {
        propertiesFileMap = new HashMap<String, Properties>();
    }
    String propFileName = fixPropertitiesFileName(propertiesFileName);
    String propKey = getPropertiesFileKey(propFileName);
    //get properties object by key.
    p = propertiesFileMap.get(propKey);
    if (null == p) {
        p = new Properties();
        InputStream input;
        try {

            //create input stream.
            input = CellFileUtil.getResourceAsStream(propFileName);
            //load properties file.
            p.load(input);
            //put properties file into map.
            propertiesFileMap.put(propKey, p);
        } catch (FileNotFoundException e) {
            //remove the key mapped properties file.
            propertiesFileMap.remove(propKey);
            e.printStackTrace();
        } catch (IOException e) {
            //remove the key mapped properties file.
            propertiesFileMap.remove(propKey);
            e.printStackTrace();
        }
    }
    return p;
}

From source file:edu.usc.squash.Main.java

private static HashMap<String, Module> parseQASMHF(Library library) {
    HFQParser hfqParser = null;//from  w  ww. j  a va  2s .com
    /*
     * Pass 1: Getting module info
     */
    try {
        hfqParser = new HFQParser(new FileInputStream(hfqPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    HashMap<String, Module> moduleMap = hfqParser.parse(library, true, null);

    /* 
     * In order traversal of modules
     */

    ArrayList<CalledModule> modulesList = new ArrayList<CalledModule>();
    modulesList.add(new CalledModule(moduleMap.get("main"), new ArrayList<String>()));
    while (!modulesList.isEmpty()) {
        Module module = modulesList.get(0).getModule();

        if (!module.isVisited()) {
            module.setVisited();

            ArrayList<CalledModule> calledModules = module.getChildModules();
            modulesList.addAll(calledModules);
            for (CalledModule calledModule : calledModules) {
                Module childModule = calledModule.getModule();
                for (int i = 0; i < calledModule.getOps().size(); i++) {
                    Operand operand = childModule.getOperand(i);
                    if (operand.isArray() && operand.getLength() == -1) {
                        operand.setLength(module.getOperandLength(calledModule.getOps().get(i)));
                    }
                }
            }
        }
        modulesList.remove(0);
    }

    /*
     * Pass 2: Making hierarchical QMDG
     */
    try {
        hfqParser = new HFQParser(new FileInputStream(hfqPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    HashMap<String, Module> modules = hfqParser.parse(library, false, moduleMap);

    return modules;
}

From source file:edu.gmu.csiss.automation.pacs.utils.BaseTool.java

/**
 * Write string to file/*from   w w  w  . j a  v  a 2  s.co m*/
 * @param content
 * @param filepath
 */
public static void writeString2File(String content, String filepath) {
    PrintWriter out;
    try {
        out = new PrintWriter(filepath);
        out.println(content);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:TweetAttributes.java

private static void writeOutputToFile(List<TweetAttributes> tweets, String outputFile) throws IOException {
    try {/*www. j a  va  2 s  .com*/

        File file = new File(outputFile); //Your file

        FileOutputStream fos = new FileOutputStream(file);

        PrintStream ps = new PrintStream(fos);

        System.setOut(ps);

    } catch (FileNotFoundException e) {

        e.printStackTrace();

    }

    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
    //    List<Long> output=new ArrayList<>();
    //  int count=1;
    Map<Integer, ArrayList> opmap = new HashMap<Integer, ArrayList>();

    for (TweetAttributes user : tweets) {
        if (opmap.containsKey(user.getClusterId())) {
            opmap.get(user.getClusterId()).add(user.getId());
        } else {
            ArrayList<Long> ids = new ArrayList<Long>();
            ids.add(user.getId());
            opmap.put(user.getClusterId(), ids);
        }
        //  count++;
    }

    /*   for(TweetAttributes model : tweets) {
            
          System.out.println(model.getClusterId()+" "+model.getId());
            
       }*/
    //   System.out.println(outputFile+"  "+out);
    for (Entry<Integer, ArrayList> entry : opmap.entrySet()) {
        System.out.print(entry.getKey() + "   ");
        for (Object fruitNo : entry.getValue()) {
            System.out.print(fruitNo);
            System.out.print(", ");
        }
        System.out.println();
    }

}

From source file:com.esri.geoevent.solutions.adapter.cot.CoTUtilities.java

private static String getStringFromFile(InputStream is) {
    StringBuffer strContent = new StringBuffer("");

    try {//from   w w  w. j  a  v  a  2 s.  c o  m
        int ch;

        while ((ch = is.read()) != -1)
            strContent.append((char) ch);
        is.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return strContent.toString();

}

From source file:edu.odu.cs.cs350.yellow1.ui.cli.Main.java

/**
 * Main program function. Creates and runs mutants as well as logging and output files
 * // w w w .j a va 2  s.  c o m
 * @param srcFolder Source folder for project to be mutated
 * @param fileToBeMutated Source file for project to be mutated
 * @param testSuitePath Path for test suite
 * @param goldOutput Original version output file
 * @throws BuildFileNotFoundException
 * @throws IOException
 */
@SuppressWarnings("static-access")
public static void mutate(String srcFolder, String fileToBeMutated, String testSuitePath, String goldOutput)
        throws BuildFileNotFoundException, IOException {

    //Step 1: Set up file directory paths for antRunner, jarExecutor, and fileMover

    logger = LogManager.getLogger(Main.class);
    mutLog = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs"
            + File.separator + "mutationsApplied.txt");
    aliveLog = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs"
            + File.separator + "mutationsAlive.txt");
    logFolder = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs");
    // ok because of the output on jenkins sanitize the logs directory
    if (logFolder.exists())
        if (logFolder.isDirectory())
            for (File f : logFolder.listFiles())
                f.delete();
    //give ant runer the project location
    ant = new AntRunner(srcFolder);
    ant.requiresInit(true);
    //call setup
    ant.setUp();
    a = new JavaFile();

    //give the jarUtil the  directory where to expect the jar   the directory where to put the jar
    jar = new JarUtil((srcFolder + File.separator + "bin"), (srcFolder + File.separator + "mutantDir"));

    //get a file object to the original file
    File goldFile = new File(fileToBeMutated);
    goldPath = goldFile.toPath();
    //get the bytes from it for checking if applying mutation and restore works
    goldOrgContent = Files.readAllBytes(goldPath);

    File script = new File(srcFolder + File.separator + "compare.sh");
    //build the JarExecutor using the JarExecutor
    jarExecutor = JarExecutorBuilder.pathToJarDirectory(srcFolder + File.separator + "mutantDir")
            .pathToCompareScript(script.getAbsolutePath())
            .pathToLogDir(srcFolder + File.separator + "mutantDir" + File.separator + "logs")
            .pathToGold(goldOutput.toString()).withExecutionState(ExecutionState.multiFile)
            .withTestSuitePath(testSuitePath).create();
    File tDir = new File(srcFolder + File.separator + "mutantDir");
    if (!tDir.exists())
        tDir.mkdir();
    //Create a fileMover object give it the directory where mutations will be placed   the directory of the original file location
    fMover = new FileMover(srcFolder + File.separator + "mutantDir", fileToBeMutated);
    fMover.setNoDelete(true);
    try {

        fMover.setUp();
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();

    }

    //Step2: Create and run mutants

    try {
        a.readFile(fileToBeMutated);
    } catch (IOException e) {
        e.printStackTrace();
    }

    a.executeAll();
    int mutantsCreated = a.getMutantCaseVector().getSize();
    logger.info("Created " + mutantsCreated + " Mutants");
    for (int i = 0; i < a.getMutantCaseVector().getSize(); i++) {
        a.getMutantCaseOperations(i).writeMutation(srcFolder + File.separator + "mutantDir" + File.separator
                + "Mutation" + Integer.toString(i + 1) + ".java");
    }

    //get the files into the file mover object
    fMover.pullFiles();

    //check to see if the filemover got all the files
    //assertEquals(fMover.getFileToBeMovedCount(),mutantsCreated);

    int moved = 0;
    int failed = 0;
    //move through each file moving them one by one
    while (fMover.hasMoreFiles()) {
        try {
            //move next file
            fMover.moveNextFile();

            //build the new executable
            ant.build();
            //move the created jar with correct number corresponding to the mutation created 
            jar.moveJarToDestNumbered();
            //clean the project
            ant.clean();
            //check to see if the mutation was applied
            //assertThat(additionOrgContent, IsNot.not(IsEqual.equalTo(Files.readAllBytes(additionPath))));

        } catch (FileMovingException | BuildException | TargetNotFoundException | IOException e) {

            //build failed
            if (e instanceof BuildException) {
                logger.error("Build exception " + e.getMessage());

                //restore the file back since compilation was not successful 
                fMover.restorTarget();
                //try {
                //   //check to see if the file was restored
                //   assertArrayEquals(goldOrgContent, Files.readAllBytes(goldPath));
                //} catch (IOException e1) {
                //   
                //}
                //clean the project
                try {
                    ant.clean();
                } catch (BuildException e1) {

                } catch (TargetNotFoundException e1) {

                }
                //indicate compile failure
                ++failed;
            }
            //fail();
        }

        //restore the file back to its original state
        fMover.restorTarget();
        //check to see if the file was restored
        //try {
        //   assertArrayEquals(goldOrgContent, Files.readAllBytes(goldPath));
        //} catch (IOException e) {
        //   
        //}

        //increment move count
        ++moved;
        //see if the file mover has the correct amount of mutatants still to be moved
        //assertEquals(fMover.getFileToBeMovedCount(), mutantsCreated - moved);
    }

    //set up for execution
    jarExecutor.setUp();
    //start execution of jars
    jarExecutor.start();

    //get the number of successful and failed runs
    int succesful = jarExecutor.getNumberOfMutantsKilled();
    int failurs = jarExecutor.getNumberOfMutantsNotKilled();
    int numTests = jarExecutor.getNumberOfTests();
    int total = succesful + failurs;
    String aliveFile = null;
    String newLine = System.lineSeparator();

    //Find any test jars that remain alive and write them to the log file
    List<ExecutionResults> testResults = jarExecutor.getMutationTestingResults();
    for (ExecutionResults result : testResults) {
        if (!result.isKilled()) {
            aliveFile = result.getJarName();
            FileUtils.writeStringToFile(aliveLog, aliveFile + newLine, true);
        }
    }

    //moved - failed = number of jars actually created
    moved = moved - failed;
    //see if the total number of executions equals the total amount of jars created
    //assertEquals(succesful+failurs,moved);
    logger.debug("Compilation failurs= " + failed + " total files moved= " + moved);
    logger.debug("Execution succesful=" + succesful + " Execution failurs= " + failurs);

    EOL eol = System.getProperty("os.name").toLowerCase().contains("windows") ? EOL.DOS : EOL.NIX;
    try {
        a.writeMutationsLog(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs"
                + File.separator + "mutationsApplied.txt", eol);
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    String finalOutput = "Number of tests: " + numTests + " " + "Number of mutants: " + total + " "
            + "Mutants killed: " + succesful;
    FileUtils.writeStringToFile(mutLog, newLine + finalOutput, true);

    System.out.println(finalOutput + "\n");
}

From source file:Main.java

public static Bitmap decodeFile(String path, int desWidth, int desHeight) {
    Bitmap result = null;/* www  .  java  2  s .  c o  m*/
    File f = null;
    FileInputStream fileInputStream = null;
    try {
        f = new File(path);
        if (!f.exists()) {
            return null;
        }
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        fileInputStream = new FileInputStream(f);
        BitmapFactory.decodeStream(fileInputStream, null, o);

        // Find the correct scale value. It should be the power of 2.
        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp / 2 < desWidth || height_tmp / 2 < desHeight)
                break;
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        result = BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    } catch (FileNotFoundException e) {
        logE(TAG, "error:" + e.getStackTrace());
    } finally {
        if (f != null) {
            f = null;
        }
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            fileInputStream = null;
        }
    }
    return result;
}

From source file:com.google.api.ads.adwords.jaxws.extensions.AwReporting.java

/**
 * Prints the sample properties file on the default output.
 *//*from  w  w  w .  ja  v a  2s . c om*/
private static void printSamplePropertiesFile() {

    System.out.println("\n  File: aw-report-sample.properties example");

    ClassPathResource sampleFile = new ClassPathResource("aw-report-sample.properties");
    Scanner fileScanner = null;
    try {
        fileScanner = new Scanner(sampleFile.getInputStream());
        while (fileScanner.hasNext()) {
            System.out.println(fileScanner.nextLine());
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fileScanner != null) {
            fileScanner.close();
        }
    }
}

From source file:com.mvdb.etl.actions.ActionUtils.java

public static Properties getTopProperties() {
    Properties topProps = null;/*from   ww w .  j a va2 s  .  c o m*/

    try {
        String propFileName = getAbsoluteFileName("~/.mvdb/etl.init.properties");
        Properties topProp = new Properties();
        topProp.load(new FileInputStream(propFileName));
        topProps = topProp;
        return topProps;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        logger.error("", e);
    } catch (IOException e) {
        e.printStackTrace();
        logger.error("", e);
    }

    return null;

}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

/**
 * //from www.j  ava2s  . co m
 * @param old
 *            the file to be copied/ moved
 * @param newDir
 *            the directory to copy/move the file to
 */
public static void copyToDirectory(String old, String newDir) {
    File old_file = new File(old);
    File temp_dir = new File(newDir);
    byte[] data = new byte[BUFFER];
    int read = 0;

    if (old_file.isFile() && temp_dir.isDirectory() && temp_dir.canWrite()) {
        String file_name = old.substring(old.lastIndexOf("/"), old.length());
        File cp_file = new File(newDir + file_name);

        try {
            BufferedOutputStream o_stream = new BufferedOutputStream(new FileOutputStream(cp_file));
            BufferedInputStream i_stream = new BufferedInputStream(new FileInputStream(old_file));

            while ((read = i_stream.read(data, 0, BUFFER)) != -1)
                o_stream.write(data, 0, read);

            o_stream.flush();
            i_stream.close();
            o_stream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
    } else if (old_file.isDirectory() && temp_dir.isDirectory() && temp_dir.canWrite()) {
        String files[] = old_file.list();
        String dir = newDir + old.substring(old.lastIndexOf("/"), old.length());
        int len = files.length;

        if (!new File(dir).mkdir())
            return;

        for (int i = 0; i < len; i++)
            copyToDirectory(old + "/" + files[i], dir);

    } else if (old_file.isFile() && !temp_dir.canWrite() && SimpleExplorer.rootAccess) {
        RootCommands.moveCopyRoot(old, newDir);
    } else if (!temp_dir.canWrite())
        return;

    return;
}