List of usage examples for java.lang NumberFormatException NumberFormatException
public NumberFormatException()
NumberFormatException
with no detail message. From source file:HexUtil.java
/** * Converts a String of hex characters into an array of bytes. * //www .j a v a2 s . c om * @param s * A string of hex characters (upper case or lower) of even * length. * @param out * A byte array of length at least s.length()/2 + off * @param off * The first byte to write of the array */ public static final void hexToBytes(String s, byte[] out, int off) throws NumberFormatException, IndexOutOfBoundsException { int slen = s.length(); if ((slen % 2) != 0) { s = '0' + s; } if (out.length < off + slen / 2) { throw new IndexOutOfBoundsException( "Output buffer too small for input (" + out.length + '<' + off + slen / 2 + ')'); } // Safe to assume the string is even length byte b1, b2; for (int i = 0; i < slen; i += 2) { b1 = (byte) Character.digit(s.charAt(i), 16); b2 = (byte) Character.digit(s.charAt(i + 1), 16); if ((b1 < 0) || (b2 < 0)) { throw new NumberFormatException(); } out[off + i / 2] = (byte) (b1 << 4 | b2); } }
From source file:org.vetmeduni.tools.implemented.QualityChecker.java
@Override protected void runThrowingExceptions(CommandLine cmd) throws Exception { File input = new File(getUniqueValue(cmd, "i")); long recordsToIterate; try {// ww w . j a v a 2 s.c o m String toIterate = getUniqueValue(cmd, "m"); recordsToIterate = (toIterate == null) ? QualityUtils.DEFAULT_MAX_RECORDS_TO_DETECT_QUALITY : Long.parseLong(toIterate); if (recordsToIterate < 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { throw new ToolException("Number of reads should be a positive long"); } logCmdLine(cmd); FastqQualityFormat format = QualityUtils.getFastqQualityFormat(input, recordsToIterate); String toConsole = (format == FastqQualityFormat.Standard) ? "Sanger" : "Illumina"; System.out.println(toConsole); }
From source file:at.alladin.rmbt.statisticServer.UsageJSONResource.java
@Get("json") public String request(final String entity) { JSONObject result = new JSONObject(); int month = -1; int year = -1; try {/* www . j a v a 2 s. c o m*/ //parameters final Form getParameters = getRequest().getResourceRef().getQueryAsForm(); try { if (getParameters.getNames().contains("month")) { month = Integer.parseInt(getParameters.getFirstValue("month")); if (month > 11 || month < 0) { throw new NumberFormatException(); } } if (getParameters.getNames().contains("year")) { year = Integer.parseInt(getParameters.getFirstValue("year")); if (year < 0) { throw new NumberFormatException(); } } } catch (NumberFormatException e) { return "invalid parameters"; } Calendar now = new GregorianCalendar(); Calendar monthBegin = new GregorianCalendar((year > 0) ? year : now.get(Calendar.YEAR), (month >= 0) ? month : now.get(Calendar.MONTH), 1); Calendar monthEnd = new GregorianCalendar((year > 0) ? year : now.get(Calendar.YEAR), (month >= 0) ? month : now.get(Calendar.MONTH), monthBegin.getActualMaximum(Calendar.DAY_OF_MONTH)); //if now -> do not use the last day if (month == now.get(Calendar.MONTH) && year == now.get(Calendar.YEAR)) { monthEnd = now; monthEnd.add(Calendar.DATE, -1); } JSONObject platforms = getPlatforms(new Timestamp(monthBegin.getTimeInMillis()), new Timestamp(monthEnd.getTimeInMillis())); JSONObject usage = getClassicUsage(new Timestamp(monthBegin.getTimeInMillis()), new Timestamp(monthEnd.getTimeInMillis())); JSONObject versionsIOS = getVersions("iOS", new Timestamp(monthBegin.getTimeInMillis()), new Timestamp(monthEnd.getTimeInMillis())); JSONObject versionsAndroid = getVersions("Android", new Timestamp(monthBegin.getTimeInMillis()), new Timestamp(monthEnd.getTimeInMillis())); JSONObject versionsApplet = getVersions("Applet", new Timestamp(monthBegin.getTimeInMillis()), new Timestamp(monthEnd.getTimeInMillis())); JSONObject networkGroupNames = getNetworkGroupName(new Timestamp(monthBegin.getTimeInMillis()), new Timestamp(monthEnd.getTimeInMillis())); JSONObject networkGroupTypes = getNetworkGroupType(new Timestamp(monthBegin.getTimeInMillis()), new Timestamp(monthEnd.getTimeInMillis())); result.put("platforms", platforms); result.put("usage", usage); result.put("versions_ios", versionsIOS); result.put("versions_android", versionsAndroid); result.put("versions_applet", versionsApplet); result.put("network_group_names", networkGroupNames); result.put("network_group_types", networkGroupTypes); } catch (SQLException e) { e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result.toString(); }
From source file:org.openhab.binding.darksky.internal.config.DarkSkyChannelConfiguration.java
/** * Parses a hh:mm string and returns the minutes. *///from w ww . j av a2s.c o m private long getMinutesFromTime(@Nullable String configTime) { String time = StringUtils.trimToNull(configTime); if (time != null) { try { if (!HHMM_PATTERN.matcher(time).matches()) { throw new NumberFormatException(); } else { String[] splittedConfigTime = time.split(TIME_SEPARATOR); int hour = Integer.parseInt(splittedConfigTime[0]); int minutes = Integer.parseInt(splittedConfigTime[1]); return Duration.ofMinutes(minutes).plusHours(hour).toMinutes(); } } catch (Exception ex) { logger.warn( "Cannot parse channel configuration '{}' to hour and minutes, use pattern hh:mm, ignoring!", time); } } return 0; }
From source file:com.AandC.GemsCraft.Configuration.ConfigActivity.java
public void save(View v) { try {//from ww w .j av a2 s .c o m String name = textBoxes[0].getText().toString(); String Port = textBoxes[1].getText().toString(); String MO = textBoxes[2].getText().toString(); int FormattedPort = Integer.parseInt(Port); if (FormattedPort >= 65535 || FormattedPort < 0) { throw new NumberFormatException(); } if (name.length() > 40) { throw new ServerNameFormatException(); } try { ConfigKey.setServerName(); ConfigKey.setPort(); ConfigKey.setMOTD(); MsgBox.show("Server Name = " + textBoxes[0].getText().toString(), "MOTD = " + textBoxes[2].getText().toString(), this); Config.writeConfig(); } catch (Exception e) { MsgBox.show("Errors", "There was a serious error that has caused the app to close", this); System.exit(0); } } catch (NullPointerException ex) { MsgBox.show("Errors", "Please fill in all items", this); } catch (NumberFormatException ex) { MsgBox.show("Errors", "Invalid Port", this); } catch (ServerNameFormatException ex) { MsgBox.show("Errors", "Server Name is too long!", this); } }
From source file:com.clustercontrol.agent.custom.CommandResultForwarder.java
private CommandResultForwarder() { {// ww w .j a v a2 s .c o m String key = "monitor.custom.forwarding.queue.maxsize"; int valueDefault = 5000; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _queueMaxSize = value; } { String key = "monitor.custom.forwarding.transport.maxsize"; int valueDefault = 100; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxSize = value; } { String key = "monitor.custom.forwarding.transport.maxtries"; int valueDefault = 900; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxTries = value; } { String key = "monitor.custom.forwarding.transport.interval.size"; int valueDefault = 15; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalSize = value; } { String key = "monitor.custom.forwarding.transport.interval.msec"; long valueDefault = 1000L; String str = AgentProperties.getProperty(key); long value = valueDefault; try { value = Long.parseLong(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalMSec = value; } _scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { private volatile int _count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, CommandResultForwarder.class.getSimpleName() + _count++); t.setDaemon(true); return t; } }); if (_transportIntervalMSec != -1) { _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec, TimeUnit.MILLISECONDS); } }
From source file:com.clustercontrol.agent.log.LogfileResultForwarder.java
private LogfileResultForwarder() { {/* w ww . j a v a2 s . com*/ String key = "monitor.logfile.forwarding.queue.maxsize"; int valueDefault = 5000; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _queueMaxSize = value; } { String key = "monitor.logfile.forwarding.transport.maxsize"; int valueDefault = 100; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxSize = value; } { String key = "monitor.logfile.forwarding.transport.maxtries"; int valueDefault = 900; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxTries = value; } { String key = "monitor.logfile.forwarding.transport.interval.size"; int valueDefault = 15; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalSize = value; } { String key = "monitor.logfile.forwarding.transport.interval.msec"; long valueDefault = 1000L; String str = AgentProperties.getProperty(key); long value = valueDefault; try { value = Long.parseLong(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalMSec = value; } _scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { private volatile int _count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, LogfileResultForwarder.class.getSimpleName() + _count++); t.setDaemon(true); return t; } }); if (_transportIntervalMSec != -1) { _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec, TimeUnit.MILLISECONDS); } }
From source file:com.clustercontrol.agent.winevent.WinEventResultForwarder.java
private WinEventResultForwarder() { {//from ww w . j a v a 2 s. c om String key = "monitor.winevent.forwarding.queue.maxsize"; int valueDefault = 5000; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _queueMaxSize = value; } { String key = "monitor.winevent.forwarding.transport.maxsize"; int valueDefault = 100; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxSize = value; } { String key = "monitor.winevent.forwarding.transport.maxtries"; int valueDefault = 900; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportMaxTries = value; } { String key = "monitor.winevent.forwarding.transport.interval.size"; int valueDefault = 15; String str = AgentProperties.getProperty(key); int value = valueDefault; try { value = Integer.parseInt(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalSize = value; } { String key = "monitor.winevent.forwarding.transport.interval.msec"; long valueDefault = 1000L; String str = AgentProperties.getProperty(key); long value = valueDefault; try { value = Long.parseLong(str); if (value != -1 && value < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { value = valueDefault; } finally { log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")"); } _transportIntervalMSec = value; } _scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { private volatile int _count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, WinEventResultForwarder.class.getSimpleName() + _count++); t.setDaemon(true); return t; } }); if (_transportIntervalMSec != -1) { _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec, TimeUnit.MILLISECONDS); } }
From source file:Ascii.java
/** * Parses an unsigned integer from the specified subarray of bytes. * @param b the bytes to parse//from w ww . j a va 2 s. co m * @param off the start offset of the bytes * @param len the length of the bytes * @exception NumberFormatException if the integer format was invalid */ public static int parseInt(byte[] b, int off, int len) throws NumberFormatException { int c; if (b == null || len <= 0 || !isDigit(c = b[off++])) { throw new NumberFormatException(); } int n = c - '0'; while (--len > 0) { if (!isDigit(c = b[off++])) { throw new NumberFormatException(); } n = n * 10 + c - '0'; } return n; }
From source file:de.akquinet.gomobile.androlog.test.MailReporterTest.java
public void testMail() { Log.init(getContext());/*w w w. j av a2 s .co m*/ String message = "This is a INFO test"; String tag = "my.log.info"; Log.d(tag, message); Log.i(tag, message); Log.w(tag, message); List<String> list = Log.getReportedEntries(); Assert.assertNotNull(list); Assert.assertFalse(list.isEmpty()); Assert.assertEquals(2, list.size()); // i + w Log.report(); Log.report("this is a user message", null); Exception error = new MalformedChallengeException("error message", new NumberFormatException()); Log.report(null, error); }