Example usage for java.io IOException printStackTrace

List of usage examples for java.io IOException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:net.iubris.ipc_d3.multidimensionaltimeline.CreateJson.java

public static void main(String[] args) {
    try {//from  w  w w  .  ja v  a2s .c  om
        //         String input = args[0];

        Charset encoding = Charset.defaultCharset();

        String csvFilesDir = "../";

        String redditoFileName = csvFilesDir
                + "Serie_Storiche_Istat_Reddito_Italiani_1995_-_2011_-_d3__reddito_disponibile_netto.csv";
        String redditoCSV = FileUtils.readFile(redditoFileName, encoding);

        String popolazioneFileName = csvFilesDir
                + "Serie_Storiche_Istat_Reddito_Italiani_1995_-_2011_-_d3__popolazione_residente.csv";
        String popolazioneCSV = FileUtils.readFile(popolazioneFileName, encoding);

        String occupatiFileName = csvFilesDir + "Occupati_1995-2011_-_Sheet2.csv";
        String occupatiCSV = FileUtils.readFile(occupatiFileName, encoding);

        JSONArray createdJson = new CreateJson().createJson(redditoCSV, popolazioneCSV, occupatiCSV);

        //         JSONArray adjustedTimeAndTipiSpecifici = new CreateJson().adjustTimeAndTipiSpecifici(jsonFile);
        String createdJsonString = createdJson.toString();
        FileUtils.writeToFile(createdJsonString, "../italiani_popolazione_reddito_occupazione_1995-2011.json");
        //         System.out.println( createdJson );
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:ai.susi.server.api.susi.StatusService.java

public static void main(String[] args) {
    try {/* www .j  ava  2  s  .  co m*/
        JSONObject json = status("http://loklak.org");
        JSONObject index_sizs = (JSONObject) json.get("index_sizes");
        System.out.println(json.toString());
        System.out.println(index_sizs.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:AESTest.java

public static void main(String[] args) {
    try {//  ww  w  . j  a va 2 s  . c  o  m
        if (args[0].equals("-genkey")) {
            KeyGenerator keygen = KeyGenerator.getInstance("AES");
            SecureRandom random = new SecureRandom();
            keygen.init(random);
            SecretKey key = keygen.generateKey();
            ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(args[1]));
            out.writeObject(key);
            out.close();
        } else {
            int mode;
            if (args[0].equals("-encrypt"))
                mode = Cipher.ENCRYPT_MODE;
            else
                mode = Cipher.DECRYPT_MODE;

            ObjectInputStream keyIn = new ObjectInputStream(new FileInputStream(args[3]));
            Key key = (Key) keyIn.readObject();
            keyIn.close();

            InputStream in = new FileInputStream(args[1]);
            OutputStream out = new FileOutputStream(args[2]);
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(mode, key);

            crypt(in, out, cipher);
            in.close();
            out.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:be.redlab.maven.yamlprops.create.YamlConvertCli.java

public static void main(String... args) throws IOException {
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();
    HelpFormatter formatter = new HelpFormatter();
    options.addOption(Option.builder("s").argName("source").desc("the source folder or file to convert")
            .longOpt("source").hasArg(true).build());
    options.addOption(Option.builder("t").argName("target").desc("the target file to store in")
            .longOpt("target").hasArg(true).build());
    options.addOption(Option.builder("h").desc("print help").build());

    try {/*from w ww. j a  v  a  2  s .  co  m*/
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption('h')) {
            formatter.printHelp("converter", options);
        }
        File source = new File(cmd.getOptionValue("s", System.getProperty("user.dir")));
        String name = source.getName();
        if (source.isDirectory()) {
            PropertiesToYamlConverter yamlConverter = new PropertiesToYamlConverter();
            String[] ext = { "properties" };
            Iterator<File> fileIterator = FileUtils.iterateFiles(source, ext, true);
            while (fileIterator.hasNext()) {
                File next = fileIterator.next();
                System.out.println(next);
                String s = StringUtils.removeStart(next.getParentFile().getPath(), source.getPath());
                System.out.println(s);
                String f = StringUtils.split(s, IOUtils.DIR_SEPARATOR)[0];
                System.out.println("key = " + f);
                Properties p = new Properties();
                try {
                    p.load(new FileReader(next));
                    yamlConverter.addProperties(f, p);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileWriter fileWriter = new FileWriter(
                    new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml"));
            yamlConverter.writeYaml(fileWriter);
            fileWriter.close();
        } else {
            Properties p = new Properties();
            p.load(new FileReader(source));
            FileWriter fileWriter = new FileWriter(
                    new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml"));
            new PropertiesToYamlConverter().addProperties(name, p).writeYaml(fileWriter);
            fileWriter.close();
        }
    } catch (ParseException e) {
        e.printStackTrace();
        formatter.printHelp("converter", options);
    }
}

From source file:DruidThroughput.java

@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
    final int numQueries = QUERIES.length;
    final Random random = new Random(RANDOM_SEED);
    final AtomicInteger counter = new AtomicInteger(0);
    final AtomicLong totalResponseTime = new AtomicLong(0L);
    final ExecutorService executorService = Executors.newFixedThreadPool(NUM_CLIENTS);

    for (int i = 0; i < NUM_CLIENTS; i++) {
        executorService.submit(new Runnable() {
            @Override/* w w  w  . jav  a  2  s .  c  om*/
            public void run() {
                try (CloseableHttpClient client = HttpClients.createDefault()) {
                    HttpPost post = new HttpPost("http://localhost:8082/druid/v2/?pretty");
                    post.addHeader("content-type", "application/json");
                    CloseableHttpResponse res;
                    while (true) {
                        try (BufferedReader reader = new BufferedReader(new FileReader(
                                QUERY_FILE_DIR + File.separator + random.nextInt(numQueries) + ".json"))) {
                            int length = reader.read(BUFFER);
                            post.setEntity(new StringEntity(new String(BUFFER, 0, length)));
                        }
                        long start = System.currentTimeMillis();
                        res = client.execute(post);
                        res.close();
                        counter.getAndIncrement();
                        totalResponseTime.getAndAdd(System.currentTimeMillis() - start);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    long startTime = System.currentTimeMillis();
    while (true) {
        Thread.sleep(REPORT_INTERVAL_MILLIS);
        double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND;
        int count = counter.get();
        double avgResponseTime = ((double) totalResponseTime.get()) / count;
        System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: "
                + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms");
    }
}

From source file:com.gagein.crawler.Extractor.java

public static void main(String[] args) {
    String website = "http://www.gagein.com";
    String tempName = "temp";
    // ???//  w  w w  .  jav  a  2  s. c o m
    String dirPath = System.getProperty("user.dir") + File.separator + tempName + File.separator
            + website.substring(7).split("\\.")[1];// remove http://;
    Extractor ex = new Extractor();
    ex.getFilesPath(dirPath);
    System.out.println(ex.pathSet);
    ArticleStripper as = new ArticleStripper();
    as.setExtractAuthor(false);
    as.setExtractContent(true);
    as.setExtractDate(false);
    as.setExtractImg(false);
    as.setKeepContentLink(false);
    for (String url : ex.pathSet) {
        System.out.println(url);
        File file = new File(url);
        try {
            String page = FileUtils.readFileToString(file);
            System.out.println("Contents of file: " + page);
            logger.debug("==============?" + url + "?");
            Article article = as.retrieveArticle(null, null, page, null);
            System.out.println("##################" + article.getContent());

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

}

From source file:net.iubris.ipc_d3.timeline.DateToEpochFormatterAndReduceTipiSpecifici.java

public static void main(String[] args) {
    try {// w w w . java2 s.  co  m
        //         String input = args[0];
        String input = "../divertimento_e_ristoro_-_timeline.json";
        input = "../../data/divertimento_e_ristoro.csv";
        String jsonFile = FileUtils.readFile(input, Charset.defaultCharset());
        JSONArray adjustedTimeAndTipiSpecifici = new DateToEpochFormatterAndReduceTipiSpecifici()
                .adjustTimeAndTipiSpecifici(jsonFile);
        String adjustedTimeAndTipiSpecificiString = adjustedTimeAndTipiSpecifici.toString();
        FileUtils.writeToFile(adjustedTimeAndTipiSpecificiString, "../divertimento_e_ristoro_-_timeline.json");
        //         System.out.println( adjustedTimeAndTipiSpecificiString );
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:examples.chargen.java

public static final void main(String[] args) {

    if (args.length == 1) {
        try {/*www. jav  a  2s  . c  o m*/
            chargenTCP(args[0]);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else if (args.length == 2 && args[0].equals("-udp")) {
        try {
            chargenUDP(args[1]);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        System.err.println("Usage: chargen [-udp] <hostname>");
        System.exit(1);
    }

}

From source file:net.padlocksoftware.padlock.keymaker.Main.java

/**
 * @param args the command line arguments
 *///from www  . j  av a  2s .c om
public static void main(String[] args) {

    int keySize = 1024;
    File file = null;

    if (args.length < 1 || args.length > 3) {
        showUsageAndExit();
    }

    for (int x = 0; x < args.length; x++) {
        String arg = args[x];

        if (arg.equals("-s")) {
            try {
                x++;
            } catch (Exception e) {
                showUsageAndExit();
            }
        } else {
            file = new File(arg);
        }
    }

    KeyPair pair = KeyManager.createKeyPair();
    try {
        KeyManager.exportKeyPair(pair, file);
        String[] lines = formatOutput(new String(Hex.encodeHex(pair.getPublic().getEncoded())));
        System.out.println("Your public key code: \n");
        for (int x = 0; x < lines.length; x++) {
            String line = lines[x];
            if (x == 0) {
                // First line
                System.out.println("\t private static final String publicKey = \n\t\t\"" + line + "\" + ");
            } else if (x == lines.length - 1) {
                // Last line
                System.out.println("\t\t\"" + line + "\";\n");
            } else {
                System.out.println("\t\t\"" + line + "\" + ");
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:examples.unix.chargen.java

public static void main(String[] args) {

    if (args.length == 1) {
        try {/*from   w w  w.  j  av  a2s .c  om*/
            chargenTCP(args[0]);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else if (args.length == 2 && args[0].equals("-udp")) {
        try {
            chargenUDP(args[1]);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        System.err.println("Usage: chargen [-udp] <hostname>");
        System.exit(1);
    }

}