Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

In this page you can find the example usage for java.lang NumberFormatException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] argv) {

    String sValue = "5";

    try {/*from  ww w.  ja  va2  s  . c om*/
        int iValue = new Integer(sValue).intValue();
    } catch (NumberFormatException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] argv) {
    String sValue = "5";
    try {//from  ww  w  .j a  v  a2  s  . c om
        int iValue = Integer.parseInt(sValue);
        System.out.println(iValue);
    } catch (NumberFormatException ex) {
        ex.printStackTrace();
    }

}

From source file:org.apache.hadoop.chukwa.inputtools.jplugin.JPluginAgent.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java -DPERIOD=nn JavaPluginAgent <class name> [parameters]");
        System.exit(0);//from   w w  w.  j  av  a  2 s.c o  m
    }

    int period = -1;
    try {
        if (System.getProperty("PERIOD") != null) {
            period = Integer.parseInt(System.getProperty("PERIOD"));
        }
    } catch (NumberFormatException ex) {
        ex.printStackTrace();
        System.out.println("PERIOD should be numeric format of seconds.");
        System.exit(0);
    }

    JPlugin plugin = null;
    try {
        plugin = (JPlugin) Class.forName(args[0]).newInstance();
        plugin.init(args);
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }

    try {
        DaemonWatcher.createInstance(plugin.getRecordType() + "-data-loader");
    } catch (Exception e) {
        e.printStackTrace();
    }

    Calendar cal = Calendar.getInstance();
    long now = cal.getTime().getTime();
    cal.set(Calendar.SECOND, 3);
    cal.set(Calendar.MILLISECOND, 0);
    cal.add(Calendar.MINUTE, 1);
    long until = cal.getTime().getTime();
    try {
        if (period == -1) {
            new MetricsTimerTask(plugin).run();
        } else {
            Thread.sleep(until - now);
            Timer timer = new Timer();
            timer.scheduleAtFixedRate(new MetricsTimerTask(plugin), 0, period * 1000);
        }
    } catch (Exception ex) {
    }
}

From source file:com.ifeng.sorter.NginxApp.java

public static void main(String[] args) {

    String input = "src/test/resources/data/nginx_report.txt";

    PrintWriter pw = null;/*from w  ww  .ja v a 2 s .  c  om*/

    Map<String, List<LogBean>> resultMap = new HashMap<String, List<LogBean>>();
    List<String> ips = new ArrayList<String>();

    try {
        List<String> lines = FileUtils.readLines(new File(input));
        List<LogBean> items = new ArrayList<LogBean>();

        for (String line : lines) {
            String[] values = line.split("\t");

            if (values != null && values.length == 3) {// ip total seria
                try {
                    String ip = values[0].trim();
                    String total = values[1].trim();
                    String seria = values[2].trim();

                    LogBean bean = new LogBean(ip, Integer.parseInt(total), seria);

                    items.add(bean);

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

        Collections.sort(items);

        for (LogBean bean : items) {
            String key = bean.getIp();

            if (resultMap.containsKey(key)) {
                resultMap.get(key).add(bean);
            } else {
                List<LogBean> keyList = new ArrayList<LogBean>();
                keyList.add(bean);
                resultMap.put(key, keyList);

                ips.add(key);
            }
        }

        pw = new PrintWriter("src/test/resources/output/result.txt", "UTF-8");

        for (String ip : ips) {
            List<LogBean> list = resultMap.get(ip);

            for (LogBean bean : list) {
                pw.append(bean.toString());
                pw.println();
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        pw.flush();
        pw.close();
    }
}

From source file:examples.ntp.SimpleNTPServer.java

public static void main(String[] args) {
    int port = NtpV3Packet.NTP_PORT;
    if (args.length != 0) {
        try {/*  w  ww  . j av  a 2s . c  o m*/
            port = Integer.parseInt(args[0]);
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }
    SimpleNTPServer timeServer = new SimpleNTPServer(port);
    try {
        timeServer.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.cloudera.recordbreaker.learnstructure.test.GenerateRandomData.java

/**
 *//*from  w w  w.ja v a  2 s  .  com*/
public static void main(String argv[]) throws IOException {
    CommandLine cmd = null;
    Options options = new Options();
    options.addOption("?", false, "Help for command-line");
    options.addOption("n", true, "Number elts to emit");

    try {
        CommandLineParser parser = new PosixParser();
        cmd = parser.parse(options, argv);
    } catch (ParseException pe) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateRandomData", options, true);
        System.exit(-1);
    }

    if (cmd.hasOption("?")) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateRandomData", options, true);
        System.exit(0);
    }

    int numToEmit = 100;
    if (cmd.hasOption("n")) {
        try {
            numToEmit = Integer.parseInt(cmd.getOptionValue("n"));
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }

    String[] argArray = cmd.getArgs();
    if (argArray.length == 0) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateRandomData", options, true);
        System.exit(0);
    }
    File inputSchemaFile = new File(argArray[0]).getCanonicalFile();
    File outputDataFile = new File(argArray[1]).getCanonicalFile();
    if (outputDataFile.exists()) {
        System.err.println("Output file already exists: " + outputDataFile.getCanonicalPath());
        System.exit(0);
    }

    GenerateRandomData grd = new GenerateRandomData();
    Schema schema = Schema.parse(inputSchemaFile);

    GenericDatumWriter datum = new GenericDatumWriter(schema);
    DataFileWriter out = new DataFileWriter(datum);
    out.create(schema, outputDataFile);
    try {
        for (int i = 0; i < numToEmit; i++) {
            out.append((GenericData.Record) grd.generateData(schema));
        }
    } finally {
        out.close();
    }
}

From source file:org.gbif.portal.util.geospatial.CellIdUtils.java

/**
 * For ease of conversion//ww w . j a v a  2 s . co m
 *
 * @param args See usage
 */
public static void main(String[] args) {
    try {
        if (args.length == 1) {
            LatLongBoundingBox llbb = toBoundingBox(Integer.parseInt(args[0]));
            System.out.println("CellId " + args[0] + ": minX[" + llbb.getMinLong() + "] minY["
                    + llbb.getMinLat() + "] maxX[" + llbb.getMaxLong() + "] maxY[" + llbb.getMaxLat() + "]");
        } else if (args.length == 2) {
            float lat = Float.parseFloat(args[0]);
            float lon = Float.parseFloat(args[1]);
            System.out.println("lat[" + lat + "] long[" + lon + "] = cellId: " + toCellId(lat, lon));
        } else {
            System.out.println("Provide either a 'cell id' or 'Lat Long' params!");
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (UnableToGenerateCellIdException e) {
        e.printStackTrace();
    }
}

From source file:com.cloudera.learnavro.test.GenerateTestAvro.java

/**
 *///from  ww  w  .ja  va 2s  .c  om
public static void main(String argv[]) throws IOException, InstantiationException {
    CommandLine cmd = null;
    Options options = new Options();
    options.addOption("?", false, "Help for command-line");
    options.addOption("n", true, "# tuples to emit per file");

    try {
        CommandLineParser parser = new PosixParser();
        cmd = parser.parse(options, argv);
    } catch (ParseException pe) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateTestAvro", options, true);
        System.exit(-1);
    }

    if (cmd.hasOption("?")) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateTestAvro", options, true);
        System.exit(0);
    }

    int numToEmit = 100;
    if (cmd.hasOption("n")) {
        try {
            numToEmit = Integer.parseInt(cmd.getOptionValue("n"));
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }

    String[] argArray = cmd.getArgs();
    if (argArray.length == 0) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("GenerateTestAvro", options, true);
        System.exit(0);
    }
    File outputDir = new File(argArray[0]).getCanonicalFile();

    GenerateTestAvro gta = new GenerateTestAvro();
    gta.generateData(outputDir, numToEmit);
}

From source file:net.semanticmetadata.lire.solr.ParallelSolrIndexer.java

public static void main(String[] args) throws IOException {
    BitSampling.readHashFunctions();/*from  w  w w.  ja va  2 s  .  c om*/
    ParallelSolrIndexer e = new ParallelSolrIndexer();

    // parse programs args ...
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.startsWith("-i")) {
            // infile ...
            if ((i + 1) < args.length)
                e.setFileList(new File(args[i + 1]));
            else {
                System.err.println("Could not set out file.");
                printHelp();
            }
        } else if (arg.startsWith("-o")) {
            // out file, if it's not set a single file for each input image is created.
            if ((i + 1) < args.length)
                e.setOutFile(new File(args[i + 1]));
            else
                printHelp();
        } else if (arg.startsWith("-m")) {
            // out file
            if ((i + 1) < args.length) {
                try {
                    int s = Integer.parseInt(args[i + 1]);
                    if (s > 10)
                        e.setMaxSideLength(s);
                } catch (NumberFormatException e1) {
                    e1.printStackTrace();
                    printHelp();
                }
            } else
                printHelp();
        } else if (arg.startsWith("-r")) {
            // image data processor class.
            if ((i + 1) < args.length) {
                try {
                    Class<?> imageDataProcessorClass = Class.forName(args[i + 1]);
                    if (imageDataProcessorClass.newInstance() instanceof ImageDataProcessor)
                        e.setImageDataProcessor(imageDataProcessorClass);
                } catch (Exception e1) {
                    System.err.println("Did not find imageProcessor class: " + e1.getMessage());
                    printHelp();
                    System.exit(0);
                }
            } else
                printHelp();
        } else if (arg.startsWith("-f") || arg.startsWith("--force")) {
            e.setForce(true);
        } else if (arg.startsWith("-y") || arg.startsWith("--features")) {
            if ((i + 1) < args.length) {
                // parse and check the features.
                String[] ft = args[i + 1].split(",");
                for (int j = 0; j < ft.length; j++) {
                    String s = ft[j].trim();
                    if (FeatureRegistry.getClassForCode(s) != null) {
                        e.addFeature(FeatureRegistry.getClassForCode(s));
                    }
                }
            }
        } else if (arg.startsWith("-p")) {
            e.setPreprocessing(true);
        } else if (arg.startsWith("-h")) {
            // help
            printHelp();
            System.exit(0);
        } else if (arg.startsWith("-n")) {
            if ((i + 1) < args.length)
                try {
                    ParallelSolrIndexer.numberOfThreads = Integer.parseInt(args[i + 1]);
                } catch (Exception e1) {
                    System.err.println("Could not set number of threads to \"" + args[i + 1] + "\".");
                    e1.printStackTrace();
                }
            else
                printHelp();
        }
    }
    // check if there is an infile, an outfile and some features to extract.
    if (!e.isConfigured()) {
        printHelp();
    } else {
        e.run();
    }
}

From source file:net.socket.bio.TimeClient.java

/**
 * @param args/*from   ww w  .j av  a  2  s .c om*/
 */
public static void main(String[] args) {

    int port = 8089;
    if (args != null && args.length > 0) {

        try {
            port = Integer.valueOf(args[0]);
        } catch (NumberFormatException e) {
            // 
        }

    }
    Socket socket = null;
    BufferedReader in = null;
    PrintWriter out = null;
    try {
        socket = new Socket("127.0.0.1", port);
        in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        out = new PrintWriter(socket.getOutputStream(), true);
        out.println("QUERY TIME ORDER");
        out.println("QUERY TIME ORDER");
        String test = StringUtils.repeat("hello tcp", 1000);
        out.println(test);
        System.out.println("Send order 2 server succeed.");
        String resp = in.readLine();
        System.out.println("Now is : " + resp);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(out);
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(socket);
    }
}