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.yodlee.sampleapps.helper.OpenSamlHelper.java

/**
 * Initilize the Keystore./*  w ww  .j  a  va2 s .c om*/
 */
private static void initKeyStore() {
    InputStream fileInput = null;
    try {
        fileInput = new FileInputStream(keystoreFilename);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
    KeyStore keystore = null;
    try {
        keystore = KeyStore.getInstance(KeyStore.getDefaultType());
        keystore.load(fileInput, keystorePassword.toCharArray());
        privateKey = (PrivateKey) keystore.getKey(keystoreAlias, keystorePassword.toCharArray());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }

    if (privateKey == null)
        throw new RuntimeException(keystoreAlias + " key not found in keystore " + keystoreFilename);

    X509Certificate cert = null;
    Certificate[] certificates = new Certificate[0];
    try {
        cert = (X509Certificate) keystore.getCertificate(keystoreAlias);
        certificates = keystore.getCertificateChain(keystoreAlias);
    } catch (KeyStoreException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
    if (cert == null)
        throw new RuntimeException(keystoreAlias + " cert not found in keystore " + keystoreFilename);

    if (certificates == null)
        throw new RuntimeException(keystoreAlias + " cert chain not found in keystore " + keystoreFilename);

    certs = new X509Certificate[certificates.length];
    System.arraycopy(certificates, 0, certs, 0, certs.length);
}

From source file:de.mpg.escidoc.util.Util.java

public static String xmlToString(final Document xmlDocument) {
    XMLOutputter outputter = new XMLOutputter();
    FileOutputStream output;/* www  . ja  va 2  s  .  com*/
    try {
        output = new FileOutputStream(XML_LOG_FILE);
        outputter.output(xmlDocument, output);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    outputter.setFormat(Format.getPrettyFormat());
    String s = outputter.outputString(xmlDocument);
    System.out.println(s);
    return s;
}

From source file:com.anyi.gp.license.RegisterTools.java

public static String readKeyFromFile(String fileName) {
    String result = "";
    File tempFile = new File(fileName);
    FileInputStream io = null;//from   w  ww. j  ava 2  s . c  om
    try {
        io = new FileInputStream(tempFile);
        byte[] buf = new byte[512];
        int size = io.read(buf);
        while (size > 0) {
            result += new String(buf, 0, size);
            size = io.read(buf);
        }
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (io != null)
                io.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return decodeString(result);
}

From source file:com.ibm.watson.catalyst.corpus.CorpusBuilder.java

/**
 * Gets the documents node from the corpus JSON.
 * @param aJson/*from   w  ww .java2 s  . c  o  m*/
 * @return
 */
private static JsonNode getDocumentsNode(File aJson) {
    JsonNode root;
    try {
        System.out.println("Reading tree.");
        root = MAPPER.readTree(aJson);
        System.out.println("Tree read.");
    } catch (FileNotFoundException e) {
        throw new IllegalStateException("Corpus not found: " + aJson, e);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        throw new IllegalStateException();
    } catch (IOException e) {
        throw new IllegalStateException();
    }
    JsonNode documentsNode = root.get("documents");
    return documentsNode;
}

From source file:com.google.api.ads.adwords.awreporting.server.AwReportingServer.java

/**
 * Prints the sample properties file on the default output.
 *///  w  w  w  .  j  ava 2  s.c  om
private static void printSamplePropertiesFile() {

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

    ClassPathResource sampleFile = new ClassPathResource(DAFAULT_PROPERTIES_LOCATION);
    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:nbayes_mr.NBAYES_MR.java

public static void test(String fname) {
    try {//from  w w w . ja va2s. c  o m
        Scanner s = new Scanner(new File(fname));
        Double probs[] = new Double[probhmap.size()];
        int totallines = 0;
        int positive = 0;
        //System.out.println("class:"+probhmap.size());
        while (s.hasNext()) {
            totallines++;
            String line = s.nextLine();
            String split[] = line.split(",");
            Set<String> classlist = probhmap.keySet();
            Iterator classitr = classlist.iterator();
            int classi = 0;
            double maxprob = -1.0;
            String classassg = "";
            while (classitr.hasNext()) {
                String hi = (String) classitr.next();
                //System.out.println(hi);
                probs[classi] = ((double) probhmap.get(hi) / (double) total);
                for (int i = 0; i < split.length - 1; i++) {
                    int ll = 0, ll1 = 0;
                    if (probhmap.containsKey(hi)) {
                        ll = probhmap.get(hi);
                    }
                    if (probxhmap.containsKey(split[i] + "|" + hi)) {
                        ll1 = probxhmap.get(split[i] + "|" + hi);
                    }

                    //System.out.println(split[i]);

                    if (ll1 != 0) {
                        probs[classi] *= ((double) probxhmap.get(split[i] + "|" + hi)
                                / (double) probhmap.get(hi));
                    } else {
                        probs[classi] = 0.0;
                    }
                }
                if (probs[classi] > maxprob) {
                    maxprob = probs[classi];
                    classassg = hi;
                }
                classi++;
            }
            //System.out.println(line);
            //System.out.println(split.length);

            if (classassg.equalsIgnoreCase(split[10])) {
                positive++;
            }
            //s.next();
        }
        accuracy.add((double) positive / (double) totallines);
        //Integer cnt5=count/5;
        //Scanner sc = new Scanner(new File("/" + fname));

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:nbayes_mr.NBAYES_MR.java

public static void splitter(String fname) {
    String filePath = new File("").getAbsolutePath();
    Integer count = 0;//from  ww  w .  jav  a 2s .c om
    try {
        Scanner s = new Scanner(new File(fname));
        while (s.hasNext()) {
            count++;
            s.next();
        }
        Integer cnt5 = count / 5;
        System.out.println(count);
        System.out.println(cnt5);
        Scanner sc = new Scanner(new File(fname));
        File file1 = new File("/home/hduser/data1.txt");
        File file2 = new File("/home/hduser/data2.txt");
        File file3 = new File("/home/hduser/data3.txt");
        File file4 = new File("/home/hduser/data4.txt");
        File file5 = new File("/home/hduser/data5.txt");
        file1.createNewFile();
        file2.createNewFile();
        file3.createNewFile();
        file4.createNewFile();
        file5.createNewFile();
        FileWriter fw1 = new FileWriter(file1.getAbsoluteFile());
        BufferedWriter bw1 = new BufferedWriter(fw1);
        FileWriter fw2 = new FileWriter(file2.getAbsoluteFile());
        BufferedWriter bw2 = new BufferedWriter(fw2);
        FileWriter fw3 = new FileWriter(file3.getAbsoluteFile());
        BufferedWriter bw3 = new BufferedWriter(fw3);
        FileWriter fw4 = new FileWriter(file4.getAbsoluteFile());
        BufferedWriter bw4 = new BufferedWriter(fw4);
        FileWriter fw5 = new FileWriter(file5.getAbsoluteFile());
        BufferedWriter bw5 = new BufferedWriter(fw5);
        for (int i = 0; i < cnt5; i++) {
            String l = sc.next();
            bw1.write(l + "\n");
        }
        for (int i = cnt5; i < 2 * cnt5; i++) {
            bw2.write(sc.next() + "\n");

        }
        for (int i = 2 * cnt5; i < 3 * cnt5; i++) {
            bw3.write(sc.next() + "\n");

        }
        for (int i = 3 * cnt5; i < 4 * cnt5; i++) {
            bw4.write(sc.next() + "\n");

        }
        for (int i = 4 * cnt5; i < count; i++) {
            bw5.write(sc.next() + "\n");

        }
        bw1.close();
        bw2.close();
        bw3.close();
        bw4.close();
        bw5.close();
        sc.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.ianzepp.logging.jms.service.BasicDaoTest.java

/**
 * TODO Method description for <code>readTableMigration()</code>
 * // w ww .  j av a 2s  .c  o  m
 * @param tableName
 * @return
 */
private static String readFile(String filePath) {
    StringBuffer fileData = new StringBuffer(4096);

    try {
        FileReader reader = new FileReader(filePath);
        char[] charBuffer = new char[2048];
        int readSize = -1;

        while ((readSize = reader.read(charBuffer)) >= 0) {
            fileData.append(charBuffer, 0, readSize);
        }

        reader.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return fileData.toString();
}

From source file:com.sarm.lonelyplanet.process.DestinationProcessorTest.java

@BeforeClass
public static void setUpClass() {
    logger.info("DestinationProcessorTest  Commencing loading test properties ...");
    Properties prop = new Properties();

    String propFileName = LonelyConstants.testPropertyFile;

    try (InputStream input = new FileInputStream(propFileName)) {

        if (input == null) {
            logger.debug("input Stream for test.properties file : is Null  ");
            throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
        }//from  ww  w .  j a v a  2 s .c o  m
        logger.debug("Loading properties file   " + propFileName);

        prop.load(input);
    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException  " + propFileName);
        ex.printStackTrace();
    } catch (IOException ex) {
        logger.debug("IOException  " + propFileName);
        ex.printStackTrace();
    }

    taxonomyFileName = prop.getProperty(LonelyConstants.propertyTaxonomy);
    targetLocation = prop.getProperty(LonelyConstants.propertyHtmlTarget);
    destinationFileName = prop.getProperty(LonelyConstants.propertyDestination);
    destinationsConcurrantlyExpresult = prop.getProperty(LonelyConstants.destinationsConcurrantlyExpresult);
    numOfDestinations = Integer.valueOf(prop.getProperty(LonelyConstants.numOfDestinations));
    regressDestinationfile = prop.getProperty(LonelyConstants.regressDestinationfile);
    indexOfdestInConcurrent = prop.getProperty(LonelyConstants.indexOfdestInConcurrent);
    try {
        sampleTesttaxonomies = TaxonomyProcessor.processTaxonomy(taxonomyFileName);
    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException  on file  : " + taxonomyFileName);
        ex.printStackTrace();
    } catch (JAXBException ex) {
        logger.debug("JAXBException  : ");
        ex.printStackTrace();
    }

    try {
        testMarshall(".//destinations.xml");
    } catch (JAXBException | FileNotFoundException | XMLStreamException | UnsupportedEncodingException ex) {
        ex.printStackTrace();

    }

}

From source file:com.lostad.app.base.util.DownloadUtil.java

public static void downFileAsyn(final Activity ctx, final String upgradeUrl, final String savedPath,
        final MyCallback<Boolean> callback) {
    final ProgressDialog xh_pDialog = new ProgressDialog(ctx);
    // ?//from  www  .  j ava2  s. co  m
    xh_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    // ProgressDialog 
    xh_pDialog.setTitle("???");
    // ProgressDialog???
    xh_pDialog.setMessage("...");
    // ProgressDialog
    // xh_pDialog.setIcon(R.drawable.img2);
    // ProgressDialog ??? false ??
    xh_pDialog.setIndeterminate(false);
    // ProgressDialog ?
    // xh_pDialog.setProgress(100);
    // ProgressDialog ???
    xh_pDialog.setCancelable(true);
    // ProgressDialog
    xh_pDialog.show();

    new Thread() {
        public void run() {

            boolean downloadSuccess = true;
            FileOutputStream fileOutputStream = null;
            try {
                Looper.prepare();
                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet(upgradeUrl);

                File f = new File(savedPath);
                if (!f.exists()) {
                    f.createNewFile();
                }

                HttpResponse response = client.execute(get);
                HttpEntity entity = response.getEntity();
                // ?
                Long length = entity.getContentLength();
                xh_pDialog.setMax(length.intValue());
                //
                InputStream is = entity.getContent();
                fileOutputStream = null;

                if (is != null && length > 0) {

                    fileOutputStream = new FileOutputStream(f);

                    byte[] buf = new byte[1024];
                    int ch = -1;
                    int count = 0;
                    while ((ch = is.read(buf)) != -1) {

                        if (xh_pDialog.isShowing()) {
                            fileOutputStream.write(buf, 0, ch);
                            // ?
                            count += ch;
                            xh_pDialog.setProgress(count);
                        } else {
                            downloadSuccess = false;
                            break;// ?
                        }
                    }

                } else {
                    callback.onCallback(false);
                }

                if (downloadSuccess && fileOutputStream != null) {
                    xh_pDialog.dismiss();
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    callback.onCallback(true);// ?
                }
                Looper.loop();
            } catch (FileNotFoundException e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
                xh_pDialog.dismiss();
            } catch (Exception e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
            } finally {
                try {
                    fileOutputStream.flush();
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }.start();

}