List of usage examples for java.lang NumberFormatException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.lavajug.streamcaster.server.Server.java
/** * * @param args//from ww w .jav a2 s . co m */ public static void main(String[] args) { int port = 7777; if (args.length > 0) { try { port = Integer.parseInt(args[0]); } catch (NumberFormatException ex) { showHelp(); System.out.println(ex.getLocalizedMessage()); System.exit(1); } } if (args.length > 1) { try { Configuration.load(args[1]); } catch (ParseException ex) { showHelp(); System.out.println(ex.getLocalizedMessage()); System.exit(1); } } Iterator<ImageWriter> iterator = ImageIO.getImageWritersByFormatName("png"); while (iterator.hasNext()) { ImageWriter next = iterator.next(); System.err.println(next.getOriginatingProvider().getDescription(Locale.getDefault())); } WebServer webServer = WebServers.createWebServer(port); webServer.add("/socket", new StreamWebsocketHandler()); webServer.add("/resources/.*", new ResourcesHandler()); webServer.add("/.*", new WebHandler()); webServer.uncaughtExceptionHandler(new ExceptionsHandler()); webServer.start(); }
From source file:net.bican.wordpress.Main.java
/** * @param args execute with "-?" for an explanation of args * @throws ParseException When the command line options cannot be parsed *///from w ww . jav a 2 s . co m public static void main(String[] args) throws ParseException { try { Options options = new Options(); options.addOption("?", "help", false, "Print usage information"); options.addOption("h", "url", true, "Specify the url to xmlrpc.php"); options.addOption("u", "user", true, "User name"); options.addOption("p", "pass", true, "Password"); options.addOption("a", "authors", false, "Get author list"); options.addOption("s", "slug", true, "Slug for categories"); options.addOption("pi", "parentid", true, "Parent id for categories"); options.addOption("oi", "postid", true, "Post id for pages and posts"); options.addOption("c", "categories", false, "Get category list"); options.addOption("cn", "newcategory", true, "New category (uses --slug and --parentid)"); options.addOption("pg", "pages", false, "Get page list (full)"); options.addOption("pl", "pagelist", false, "Get page list"); options.addOption("ps", "page", true, "Get page"); options.addOption("pn", "newpage", true, "New page from file <arg> (needs --publish)"); options.addOption("pe", "editpage", true, "Edit page (needs --postid and --publish"); options.addOption("pd", "deletepage", true, "Delete page (needs --publish)"); options.addOption("l", "publish", true, "Publish status for \"new\" options"); options.addOption("us", "userinfo", false, "Get user information"); options.addOption("or", "recentposts", true, "Get recent posts"); options.addOption("os", "getpost", true, "Get post"); options.addOption("on", "newpost", true, "New post from file <arg> (needs --publish)"); options.addOption("oe", "editpost", true, "Edit post (needs --postid and --publish"); options.addOption("od", "deletepost", true, "Delete post (needs --publish)"); options.addOption("sm", "supportedmethods", false, "List supported methods"); options.addOption("st", "supportedfilters", false, "List supported text filters"); options.addOption("mn", "newmedia", true, "New media file (uses --overwrite)"); options.addOption("ov", "overwrite", false, "Allow overwrite in uploading new media"); options.addOption("so", "supportedstatus", false, "Print supported page and post status values"); options.addOption("cs", "commentstatus", false, "Print comment status names for the blog"); options.addOption("cc", "commentcount", true, "Get comment count for a post (-1 for all posts)"); options.addOption("ca", "newcomment", true, "New comment from file"); options.addOption("cd", "deletecomment", true, "Delete comment"); options.addOption("ce", "editcomment", true, "Edit comment from file"); options.addOption("cg", "getcomment", true, "Get comment"); options.addOption("ct", "getcomments", true, "Get comments for the post"); options.addOption("cs", "commentstatus", true, "Comment status (for --getcomments)"); options.addOption("co", "commentoffset", true, "Comment offset # (for --getcomments)"); options.addOption("cm", "commentnumber", true, "Comment # (for --getcomments)"); try { WpCliConfiguration config = new WpCliConfiguration(args, options, Main.class); if (config.hasOption("help")) { showHelp(options); } else if ((!config.hasOption("url")) || (!config.hasOption("user")) || (!config.hasOption("pass"))) { System.err.println("Specify --user, --pass and --url"); } else { try { Wordpress wp = new Wordpress(config.getOptionValue("user"), config.getOptionValue("pass"), config.getOptionValue("url")); if (config.hasOption("authors")) { printList(wp.getAuthors(), Author.class, true); } else if (config.hasOption("categories")) { printList(wp.getCategories(), Category.class, true); } else if (config.hasOption("newcategory")) { String slug = config.getOptionValue("slug"); Integer parentId = getInteger("parentid", config); if (slug == null) slug = ""; if (parentId == null) parentId = 0; System.out .println(wp.newCategory(config.getOptionValue("newcategory"), slug, parentId)); } else if (config.hasOption("pages")) { printList(wp.getPages(), Page.class, false); } else if (config.hasOption("pagelist")) { printList(wp.getPageList(), PageDefinition.class, false); } else if (config.hasOption("page")) { printItem(wp.getPage(getInteger("page", config)), Page.class); } else if (config.hasOption("userinfo")) { printItem(wp.getUserInfo(), User.class); } else if (config.hasOption("recentposts")) { printList(wp.getRecentPosts(getInteger("recentposts", config)), Page.class, false); } else if (config.hasOption("getpost")) { printItem(wp.getPost(getInteger("getpost", config)), Page.class); } else if (config.hasOption("supportedmethods")) { printList(wp.supportedMethods(), String.class, false); } else if (config.hasOption("supportedfilters")) { printList(wp.supportedTextFilters(), String.class, false); } else if (config.hasOption("newpage")) { if (!config.hasOption("publish")) { showHelp(options); } else { System.out.println( wp.newPage(Page.fromFile(new File(config.getOptionValue("newpage"))), config.getOptionValue("publish"))); } } else if (config.hasOption("editpage")) { edit(options, config, wp, "editpage", true); } else if (config.hasOption("editpost")) { edit(options, config, wp, "editpost", false); } else if (config.hasOption("deletepage")) { delete(options, config, wp, "deletepage", true); } else if (config.hasOption("deletepost")) { delete(options, config, wp, "deletepost", false); } else if (config.hasOption("newpost")) { if (!config.hasOption("publish")) { showHelp(options); } else { System.out.println( wp.newPost(Page.fromFile(new File(config.getOptionValue("newpost"))), Boolean.valueOf(config.getOptionValue("publish")))); } } else if (config.hasOption("newmedia")) { String fileName = config.getOptionValue("newmedia"); File file = new File(fileName); String mimeType = new MimetypesFileTypeMap().getContentType(file); Boolean overwrite = Boolean.FALSE; if (config.hasOption("overwrite")) overwrite = Boolean.TRUE; MediaObject result = wp.newMediaObject(mimeType, file, overwrite); if (result != null) { System.out.println(result); } } else if (config.hasOption("supportedstatus")) { System.out.println("Recognized status values for posts:"); printList(wp.getPostStatusList(), PostAndPageStatus.class, true); System.out.println("\nRecognized status values for pages:"); printList(wp.getPageStatusList(), PostAndPageStatus.class, true); } else if (config.hasOption("commentstatus")) { showCommentStatus(wp); } else if (config.hasOption("commentcount")) { showCommentCount(config, wp); } else if (config.hasOption("newcomment")) { editComment(wp, config.getOptionValue("newcomment"), "newcomment"); } else if (config.hasOption("editcomment")) { editComment(wp, config.getOptionValue("editcomment"), "editcomment"); } else if (config.hasOption("deletecomment")) { System.err.println(Integer.valueOf(config.getOptionValue("deletecomment"))); deleteComment(wp, Integer.valueOf(config.getOptionValue("deletecomment"))); } else if (config.hasOption("getcomment")) { printComment(wp, Integer.valueOf(config.getOptionValue("getcomment"))); } else if (config.hasOption("getcomments")) { Integer postID = Integer.valueOf(config.getOptionValue("getcomments")); String commentStatus = config.getOptionValue("commentstatus"); Integer commentOffset; try { commentOffset = Integer.valueOf(config.getOptionValue("commentoffset")); } catch (NumberFormatException e) { commentOffset = null; } Integer commentNumber; try { commentNumber = Integer.valueOf(config.getOptionValue("commentnumber")); } catch (Exception e) { commentNumber = null; } printComments(wp, postID, commentStatus, commentOffset, commentNumber); } else { showHelp(options); } } catch (MalformedURLException e) { System.err.println("URL \"" + config.getOptionValue("url") + "\" is invalid, reason is: " + e.getLocalizedMessage()); } catch (IOException e) { System.err.println("Can't read from file, reason is: " + e.getLocalizedMessage()); } catch (InvalidPostFormatException e) { System.err.println("Input format is invalid."); } } } catch (ParseException e) { System.err.println("Can't process command line arguments, reason is: " + e.getLocalizedMessage()); } } catch (XmlRpcFault e) { String reason = e.getLocalizedMessage(); System.err.println("Operation failed, reason is: " + reason); } }
From source file:com.mgreau.jboss.as7.cli.CliLauncher.java
public static void main(String[] args) throws Exception { int exitCode = 0; CommandContext cmdCtx = null;// ww w .j a va 2 s. c o m boolean gui = false; String appName = ""; try { String argError = null; List<String> commands = null; File file = null; boolean connect = false; String defaultControllerProtocol = "http-remoting"; String defaultControllerHost = null; int defaultControllerPort = -1; boolean version = false; String username = null; char[] password = null; int connectionTimeout = -1; //App deployment boolean isAppDeployment = false; final Properties props = new Properties(); for (String arg : args) { if (arg.startsWith("--controller=") || arg.startsWith("controller=")) { final String fullValue; final String value; if (arg.startsWith("--")) { fullValue = arg.substring(13); } else { fullValue = arg.substring(11); } final int protocolEnd = fullValue.lastIndexOf("://"); if (protocolEnd == -1) { value = fullValue; } else { value = fullValue.substring(protocolEnd + 3); defaultControllerProtocol = fullValue.substring(0, protocolEnd); } String portStr = null; int colonIndex = value.lastIndexOf(':'); if (colonIndex < 0) { // default port defaultControllerHost = value; } else if (colonIndex == 0) { // default host portStr = value.substring(1); } else { final boolean hasPort; int closeBracket = value.lastIndexOf(']'); if (closeBracket != -1) { //possible ip v6 if (closeBracket > colonIndex) { hasPort = false; } else { hasPort = true; } } else { //probably ip v4 hasPort = true; } if (hasPort) { defaultControllerHost = value.substring(0, colonIndex).trim(); portStr = value.substring(colonIndex + 1).trim(); } else { defaultControllerHost = value; } } if (portStr != null) { int port = -1; try { port = Integer.parseInt(portStr); if (port < 0) { argError = "The port must be a valid non-negative integer: '" + args + "'"; } else { defaultControllerPort = port; } } catch (NumberFormatException e) { argError = "The port must be a valid non-negative integer: '" + arg + "'"; } } } else if ("--connect".equals(arg) || "-c".equals(arg)) { connect = true; } else if ("--version".equals(arg)) { version = true; } else if ("--gui".equals(arg)) { gui = true; } else if (arg.startsWith("--appDeployment=") || arg.startsWith("appDeployment=")) { isAppDeployment = true; appName = arg.startsWith("--") ? arg.substring(16) : arg.substring(14); } else if (arg.startsWith("--file=") || arg.startsWith("file=")) { if (file != null) { argError = "Duplicate argument '--file'."; break; } if (commands != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } final String fileName = arg.startsWith("--") ? arg.substring(7) : arg.substring(5); if (!fileName.isEmpty()) { file = new File(fileName); if (!file.exists()) { argError = "File " + file.getAbsolutePath() + " doesn't exist."; break; } } else { argError = "Argument '--file' is missing value."; break; } } else if (arg.startsWith("--commands=") || arg.startsWith("commands=")) { if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } final String value = arg.startsWith("--") ? arg.substring(11) : arg.substring(9); commands = Util.splitCommands(value); } else if (arg.startsWith("--command=") || arg.startsWith("command=")) { if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } final String value = arg.startsWith("--") ? arg.substring(10) : arg.substring(8); commands = Collections.singletonList(value); } else if (arg.startsWith("--user=")) { username = arg.startsWith("--") ? arg.substring(7) : arg.substring(5); } else if (arg.startsWith("--password=")) { password = (arg.startsWith("--") ? arg.substring(11) : arg.substring(9)).toCharArray(); } else if (arg.startsWith("--timeout=")) { if (connectionTimeout > 0) { argError = "Duplicate argument '--timeout'"; break; } final String value = arg.substring(10); try { connectionTimeout = Integer.parseInt(value); } catch (final NumberFormatException e) { // } if (connectionTimeout <= 0) { argError = "The timeout must be a valid positive integer: '" + value + "'"; } } else if (arg.equals("--help") || arg.equals("-h")) { commands = Collections.singletonList("help"); } else if (arg.startsWith("--properties=")) { final String value = arg.substring(13); final File propertiesFile = new File(value); if (!propertiesFile.exists()) { argError = "File doesn't exist: " + propertiesFile.getAbsolutePath(); break; } FileInputStream fis = null; try { fis = new FileInputStream(propertiesFile); props.load(fis); } catch (FileNotFoundException e) { argError = e.getLocalizedMessage(); break; } catch (java.io.IOException e) { argError = "Failed to load properties from " + propertiesFile.getAbsolutePath() + ": " + e.getLocalizedMessage(); break; } finally { if (fis != null) { try { fis.close(); } catch (java.io.IOException e) { } } } for (final Object prop : props.keySet()) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { System.setProperty((String) prop, (String) props.get(prop)); return null; } }); } } else if (!(arg.startsWith("-D") || arg.equals("-XX:"))) {// skip system properties and jvm options // assume it's commands if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time: " + arg; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } commands = Util.splitCommands(arg); } } if (argError != null) { System.err.println(argError); exitCode = 1; return; } if (version) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); VersionHandler.INSTANCE.handle(cmdCtx); return; } if (file != null) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); processFile(file, cmdCtx, isAppDeployment, appName, props); return; } if (commands != null) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); processCommands(commands, cmdCtx); return; } // Interactive mode cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, true, connect, connectionTimeout); cmdCtx.interact(); } catch (Throwable t) { t.printStackTrace(); exitCode = 1; } finally { if (cmdCtx != null && cmdCtx.getExitCode() != 0) { exitCode = cmdCtx.getExitCode(); } if (!gui) { System.exit(exitCode); } } System.exit(exitCode); }
From source file:Main.java
/** * Decodes data encoded using {@link #toHex(byte[],int,int) toHex}. * * @param hex data to be converted//from w w w . ja va2 s. com * @param start offset * @param len count * * @throws IOException if input does not represent hex encoded value * * @since 1.29 */ public static byte[] fromHex(char[] hex, int start, int len) throws IOException { if (hex == null) throw new IOException("null"); int i = hex.length; if (i % 2 != 0) throw new IOException("odd length"); byte[] magic = new byte[i / 2]; for (; i > 0; i -= 2) { String g = new String(hex, i - 2, 2); try { magic[(i / 2) - 1] = (byte) Integer.parseInt(g, 16); } catch (NumberFormatException ex) { throw new IOException(ex.getLocalizedMessage()); } } return magic; }
From source file:com.hybris.mobile.app.commerce.utils.ProductUtils.java
/** * Sum up quantities to get total value price and round off to 2 digit * * @param quantity : item quantity added * @param productPrice : price for single item * @return//from ww w . j a va 2s .c o m */ public static String calculateQuantityPrice(String quantity, Price productPrice) { String total = "00.00"; try { if (StringUtils.isNotBlank(quantity) && Integer.parseInt(quantity) > 0 && productPrice != null) { total = String.valueOf(Constants.PRICE_SMALL .format((Integer.parseInt(quantity) * productPrice.getValue().doubleValue()))); } } catch (NumberFormatException e) { Log.e(TAG, e.getLocalizedMessage()); } return total; }
From source file:Main.java
/** * Decodes data encoded using {@link #toHex(byte[],int,int) toHex}. * * @param hex data to be converted/*from w w w. jav a 2 s .com*/ * @param start offset * @param len count * @return the converted data * * @throws IOException if input does not represent hex encoded value * * @since 1.29 */ public static byte[] fromHex(char[] hex, int start, int len) throws IOException { if (hex == null) { throw new IOException("null"); } int i = hex.length; if ((i % 2) != 0) { throw new IOException("odd length"); } byte[] magic = new byte[i / 2]; for (; i > 0; i -= 2) { String g = new String(hex, i - 2, 2); try { magic[(i / 2) - 1] = (byte) Integer.parseInt(g, 16); } catch (NumberFormatException ex) { throw new IOException(ex.getLocalizedMessage()); } } return magic; }
From source file:com.tlabs.eve.api.parser.BaseRule.java
protected static final boolean setProperty(final Object bean, final String property, final String value) { try {/* www .j av a 2 s. c om*/ return setPropertyImpl(bean, property, value); } catch (NumberFormatException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getLocalizedMessage(), e); } return setPropertyImpl(bean, property, "0"); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getLocalizedMessage(), e); } return false; } }
From source file:com.jkoolcloud.tnt4j.streams.utils.NumericFormatter.java
/** * Formats the specified object using the defined pattern, or using the default numeric formatting if no pattern was * defined.// w w w . jav a2 s. c o m * * @param formatter * formatter object to apply to value * @param radix * the radix to use while parsing numeric strings * @param value * value to convert * @param scale * value to multiply the formatted value by * * @return formatted value of field in required internal data type * * @throws ParseException * if an error parsing the specified value based on the field definition (e.g. does not match defined * pattern, etc.) */ private static Number parse(DecimalFormat formatter, int radix, Object value, Number scale) throws ParseException { if (value == null) { return null; } if (scale == null) { scale = 1.0; } try { Number numValue = null; if (formatter == null && value instanceof String) { String strValue = (String) value; if (strValue.startsWith("0x") || strValue.startsWith("0X")) { // NON-NLS numValue = Long.parseLong(strValue.substring(2), 16); } } if (numValue == null) { if (formatter != null) { numValue = formatter.parse(value.toString()); } else if (radix != 10) { numValue = Long.parseLong(value.toString(), radix); } else { numValue = value instanceof Number ? (Number) value : Double.valueOf(value.toString()); } } Number scaledValue = numValue.doubleValue() * scale.doubleValue(); return Utils.castNumber(scaledValue, numValue.getClass()); } catch (NumberFormatException nfe) { throw new ParseException(nfe.getLocalizedMessage(), 0); } }
From source file:main.RankerOCR.java
/** * Evaluate the precision parameter.//from w w w.j a va 2s . c o m * <p> * @param s precision parameter as a string * @return Precision parameter as a integer if possible. Otherwise, stop the * program and return an error code */ private static int evalPrecisionOption(String s) { try { int precision; precision = Integer.valueOf(s); if (precision < 0) { System.exit(-2); } else if (precision > 10) { System.exit(-3); } return precision; } catch (NumberFormatException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-1); return 0; } }
From source file:org.deegree.tools.rendering.manager.PrototypeAssigner.java
private static float parseNumber(CommandLine line, String id) { try {/*from ww w.ja v a 2 s . c o m*/ return Float.parseFloat(line.getOptionValue(id)); } catch (NumberFormatException e) { throw new IllegalArgumentException(id + " must be a number: " + e.getLocalizedMessage(), e); } }