Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:HolidaySked.java

public static void main(String[] arguments) {
    HolidaySked cal = new HolidaySked();
    if (arguments.length > 0) {
        try {/*from   ww  w. j  av  a2s  .co  m*/
            int whichDay = Integer.parseInt(arguments[0]);
            if (cal.isHoliday(whichDay)) {
                System.out.println("Day number " + whichDay + " is a holiday.");
            } else {
                System.out.println("Day number " + whichDay + " is not a holiday.");
            }
        } catch (NumberFormatException nfe) {
            System.out.println("Error: " + nfe.getMessage());
        }
    }
}

From source file:Main.java

public static void main(String[] argv) {
    int number = 0;

    System.out.println("The number of words in argv is " + argv.length);

    if (argv.length == 0) {
        number = 1234;//from   w  w w .ja v  a 2 s. c o m
    } else if (argv.length == 1) {
        try {
            number = Integer.parseInt(argv[0]);
        } catch (NumberFormatException e) {
            System.err.println("Number " + argv[0] + " invalid (" + e.getMessage() + ").");
            System.exit(1);
        }
    } else {
        System.err.println("usage: UseArgv number");
        System.exit(1);
    }

    System.out.println("OK, number is " + number);
}

From source file:AddException.java

/** Main program */
public static void main(String[] argv) {
    int number = 0;

    System.out.println("The number of words in argv is " + argv.length);

    if (argv.length == 0) {
        number = 1234;//from  w  ww .  ja va2s .  c  om
    } else if (argv.length == 1) {
        try {
            number = Integer.parseInt(argv[0]);
        } catch (NumberFormatException e) {
            System.err.println("Number " + argv[0] + " invalid (" + e.getMessage() + ").");
            System.exit(1);
        }
    } else {
        System.err.println("usage: UseArgv number");
        System.exit(1);
    }

    System.out.println("OK, number is " + number);
}

From source file:ObjectTest.java

public static void main(String args[]) {
    for (int a = 0; a < args.length; a++) {
        String version = "Unknown";
        try {// w  ww .  j  a  v a2s.c om
            JSONTokener tokener = new JSONTokener(new FileInputStream(args[a]));
            JSONObject jsonSubject = new JSONObject(tokener);
            version = jsonSubject.getJSONObject("X3D").getString("@version");
            JSONObject jsonSchema = new JSONObject(new JSONTokener(
                    ObjectTest.class.getResourceAsStream("x3d-" + version + "-JSONSchema.json")));

            Schema schema = SchemaLoader.load(jsonSchema);
            schema.validate(jsonSubject);

            // System.out.println("json-schema "+version+" Valid "+args[a]);
        } catch (NullPointerException npe) {
            System.out.println("json-config " + version + " null point error " + args[a]);
        } catch (FileNotFoundException e) {
            System.out.println("json-file file missing " + e.getMessage() + " " + args[a]);
        } catch (NumberFormatException nfe) {
            System.out.println("json-parse json " + nfe.getMessage() + " " + args[a]);
        } catch (JSONException je) {
            System.out.println("json-parse json " + je.getMessage() + " " + args[a]);
        } catch (ValidationException ve) {
            Iterator<ValidationException> i = ve.getCausingExceptions().iterator();
            while (i.hasNext()) {
                ValidationException veel = i.next();
                System.out.println("json-schema " + version + " Validation error " + veel + " " + args[a]);
            }
        }
    }
}

From source file:org.ala.harvester.RawFileHarvestRunner.java

/**
* Main method/*  ww  w  .ja  v  a  2 s .c  o  m*/
 *
 * @param args
*/
public static void main(String[] args) {
    // Get Spring context
    context = new ClassPathXmlApplicationContext("classpath*:spring.xml");
    //InfoSourceDAO infoSourceDAORO = (InfoSourceDAO) context.getBean("infoSourceDao");

    RawFileHarvestRunner hr = (RawFileHarvestRunner) context.getBean("rawFileHarvestRunner");

    if (args.length < 1) {
        System.out.println(
                "Please enter an info source ID to harvest OR enter \"all\" " + "to harvest all info sources");
        System.exit(-1);
    } else if (args[0].equalsIgnoreCase("all")) {
        logger.info("Harvesting all info sources...");
        List<Integer> infoSourceIds = hr.getAllIds();
        hr.harvest(infoSourceIds);
    } else {
        try {
            Integer infoSourceId = Integer.parseInt(args[0]);
            List<Integer> infoSourceIds = new ArrayList<Integer>();
            infoSourceIds.add(infoSourceId);
            hr.harvest(infoSourceIds);
        } catch (NumberFormatException ex) {
            logger.error("info source id was not recognised as a number: " + ex.getMessage());
        }
    }
}

From source file:org.ala.harvester.HarvestRunner.java

/**
 * Main method//from w  ww. ja  va2s.c  om
 *
 * @param args
 */
public static void main(String[] args) {
    // Get Spring context
    context = new ClassPathXmlApplicationContext("classpath*:spring.xml");
    //InfoSourceDAO infoSourceDAORO = (InfoSourceDAO) context.getBean("infoSourceDao");
    HarvestRunner hr = (HarvestRunner) context.getBean("harvestRunner");

    if (args.length < 1) {
        System.out.println(
                "Please enter an info source ID to harvest OR enter \"all\" " + "to harvest all info sources");
        System.exit(-1);
    } else if (args.length < 2 && args[0].equalsIgnoreCase("all")) {
        logger.info("Harvesting all info sources...");
        List<Integer> infoSourceIds = hr.getAllIds();
        hr.harvest(infoSourceIds);
    } else if (args.length < 2) {
        try {
            Integer infoSourceId = Integer.parseInt(args[0]);
            List<Integer> infoSourceIds = new ArrayList<Integer>();
            infoSourceIds.add(infoSourceId);
            hr.harvest(infoSourceIds);
        } catch (NumberFormatException ex) {
            logger.error("info source id was not recognised as a number: " + ex.getMessage());
        }
    } else if (args.length < 3 && args[0].equalsIgnoreCase("all")) {
        try {
            Integer timeGap = Integer.parseInt(args[1]);
            logger.info("Harvesting all info sources...");
            List<Integer> infoSourceIds = hr.getAllIds();
            hr.harvest(infoSourceIds, timeGap);
        } catch (NumberFormatException ex) {
            logger.error("time gap was not recognised as a number: " + ex.getMessage());
        }
    } else if (args.length < 3) {
        try {
            Integer infoSourceId = Integer.parseInt(args[0]);
            Integer timeGap = Integer.parseInt(args[1]);
            List<Integer> infoSourceIds = new ArrayList<Integer>();
            infoSourceIds.add(infoSourceId);
            hr.harvest(infoSourceIds, timeGap);
        } catch (NumberFormatException ex) {
            logger.error("info source id was not recognised as a number: " + ex.getMessage());
        }
    }

}

From source file:cnxchecker.Server.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("p", "port", true, "TCP port to bind to (random by default)");
    options.addOption("h", "help", false, "Print help");

    CommandLineParser parser = new GnuParser();
    try {/*  w ww.  jav a 2 s . co  m*/
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp("server", options);
            System.exit(0);
        }

        int port = 0;
        if (cmd.hasOption("p")) {
            try {
                port = Integer.parseInt(cmd.getOptionValue("p"));
            } catch (NumberFormatException e) {
                printAndExit("Invalid port number " + cmd.getOptionValue("p"));
            }

            if (port < 0 || port > 65535) {
                printAndExit("Invalid port number " + port);
            }
        }

        Server server = new Server(port);
        server.doit();
    } catch (ParseException e) {
        printAndExit("Failed to parse options: " + e.getMessage());
    }
}

From source file:com.zimbra.cs.mailbox.util.MetadataDump.java

public static void main(String[] args) {
    try {//from   w  w w .  ja v a 2  s. c o  m
        CliUtil.toolSetup("WARN");
        int mboxId = 0;
        int itemId = 0;

        PrintStream out = new PrintStream(System.out, true, "utf-8");

        CommandLine cl = parseArgs(args);
        if (cl.hasOption(OPT_HELP)) {
            usage(null);
            System.exit(0);
        }

        // Get data from file.
        String infileName = cl.getOptionValue(OPT_FILE);
        if (infileName != null) {
            File file = new File(infileName);
            if (file.exists()) {
                String encoded = loadFromFile(file);
                Metadata md = new Metadata(encoded);
                String pretty = md.prettyPrint();
                out.println(pretty);
                return;
            } else {
                System.err.println("File " + infileName + " does not exist");
                System.exit(1);
            }
        }

        // Get data from input String.
        String encoded = cl.getOptionValue(OPT_STR);
        if (!StringUtil.isNullOrEmpty(encoded)) {
            Metadata md = new Metadata(encoded);
            String pretty = md.prettyPrint();
            out.println(pretty);
            return;
        }

        // Get data from db.
        DbPool.startup();
        DbConnection conn = null;

        try {
            boolean fromDumpster = cl.hasOption(OPT_DUMPSTER);
            String mboxIdStr = cl.getOptionValue(OPT_MAILBOX_ID);
            String itemIdStr = cl.getOptionValue(OPT_ITEM_ID);
            if (mboxIdStr == null || itemIdStr == null) {
                usage(null);
                System.exit(1);
                return;
            }
            if (mboxIdStr.matches("\\d+")) {
                try {
                    mboxId = Integer.parseInt(mboxIdStr);
                } catch (NumberFormatException e) {
                    System.err.println("Invalid mailbox id " + mboxIdStr);
                    System.exit(1);
                }
            } else {
                conn = DbPool.getConnection();
                mboxId = lookupMailboxIdFromEmail(conn, mboxIdStr);
            }
            try {
                itemId = Integer.parseInt(itemIdStr);
            } catch (NumberFormatException e) {
                usage(null);
                System.exit(1);
            }

            if (conn == null)
                conn = DbPool.getConnection();
            doDump(conn, mboxId, itemId, fromDumpster, out);
        } finally {
            DbPool.quietClose(conn);
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.err.println();
        System.err.println();
        e.printStackTrace();
        System.exit(1);
    }
}

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

public static void main(String[] args) throws IOException {
    BitSampling.readHashFunctions();//from   w  w w.  j  a  v a  2s. c  o m
    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:lu.tudor.santec.dicom.gui.header.Dcm2Xml.java

public static void main(String[] args) {
    CommandLine cl = parse(args);/*from  w  w w  . j a va 2  s  .co m*/
    Dcm2Xml dcm2xml = new Dcm2Xml();
    File ifile = new File((String) cl.getArgList().get(0));
    File ofile = null;
    if (cl.hasOption("o")) {
        ofile = new File(cl.getOptionValue("o"));
        dcm2xml.setBaseDir(ofile.getAbsoluteFile().getParentFile());
    }
    if (cl.hasOption("d")) {
        dcm2xml.setBaseDir(new File(cl.getOptionValue("d")));
    }
    boolean x = cl.hasOption("X");
    if (cl.hasOption("x")) {
        String[] tagStr = cl.getOptionValues("x");
        int[] excludes = new int[x ? tagStr.length + 1 : tagStr.length];
        for (int i = 0; i < tagStr.length; i++) {
            try {
                excludes[i] = (int) Long.parseLong(tagStr[i], 16);
            } catch (NumberFormatException e) {
                excludes[i] = Tag.forName(tagStr[i]);
            }
        }
        if (x) {
            excludes[tagStr.length] = Tag.PixelData;
        }
        dcm2xml.setExclude(excludes);
    } else if (x) {
        dcm2xml.setExclude(new int[] { Tag.PixelData });
    }
    if (cl.hasOption("T")) {
        final String xslurl = cl.getOptionValue("T");
        try {
            dcm2xml.setXslt(new URL(xslurl));
        } catch (MalformedURLException e) {
            System.err.println("dcm2xml: invalid xsl URL: " + xslurl);
            System.exit(1);
        }
        dcm2xml.setXsltInc(cl.hasOption("I"));
        dcm2xml.setXsltParams(cl.getOptionValues("P"));
    }
    dcm2xml.setComments(cl.hasOption("C"));
    dcm2xml.setIndent(!cl.hasOption("c"));
    long t1 = System.currentTimeMillis();
    try {
        dcm2xml.convert(ifile, ofile);
    } catch (TransformerConfigurationException e) {
        System.err.println("dcm2xml: Configuration Error: " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println("dcm2xml: Failed to convert " + ifile + ": " + e.getMessage());
        e.printStackTrace(System.err);
        System.exit(1);
    }
    long t2 = System.currentTimeMillis();
    if (ofile != null)
        System.out.println("Finished conversion of " + ifile + "to " + ofile + " in " + (t2 - t1) + "ms");
}