List of usage examples for java.lang NumberFormatException NumberFormatException
public NumberFormatException(String s)
NumberFormatException
with the specified detail message. From source file:speedith.cli.CliOptions.java
/** * Returns the sub-diagram index (or -1 if none was given). * <p>This is the value of the arguments to the {@link CliOptions#OPTION_SDI * sub-diagram index} option.</p>/*w w w.j av a 2s.c om*/ * @return the sub-diagram index (or -1 if none was given). * @throws RuntimeException if the given index is not formatted correctly. */ public int getSubDiagramIndex() { String sdi = getParsedOptions().getOptionValue(OPTION_SDI); if (sdi != null) { try { int retVal = Integer.parseInt(sdi); if (retVal < 0) { throw new NumberFormatException(i18n("GERR_NEGATIVE_INTEGER")); } return retVal; } catch (NumberFormatException nfe) { throw new RuntimeException(i18n("ERR_CLI_SDI_INVALID", sdi), nfe); } } return -1; }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.instruments.impl.starinettester.dao.StarinetTesterDAO.java
/*********************************************************************************************** * sendHttpRequest()./*from w ww .ja v a2s. c o m*/ * http://hc.apache.org/httpclient-3.x/tutorial.html * http://www.eboga.org/java/open-source/httpclient-demo.html * * @param commandmessage * * @return ResponseMessageInterface */ public ResponseMessageInterface sendHttpRequest(final CommandMessageInterface commandmessage) { final String SOURCE = "StarinetTesterDAO.sendHttpRequest()"; final int PARAMETER_COUNT = 1; final int CHANNEL_COUNT = 1; final CommandType commandType; ResponseMessageInterface responseMessage; final HttpClient client; HttpMethod method; LOGGER.debugTimedEvent(LOADER_PROPERTIES.isTimingDebug(), SOURCE); // Get the latest Resources readResources(); // Don't affect the CommandType of the incoming Command commandType = (CommandType) commandmessage.getCommandType().copy(); responseMessage = null; // Do not change any DAO data containers! clearEventLogFragment(); // Set up the HttpClient client = new HttpClient(); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, false)); // Initialise the Method with a default URL method = new GetMethod(DEFAULT_URL); try { final List<ParameterType> listParameters; // We expect one Parameter, the URL listParameters = commandType.getParameterList(); if ((listParameters != null) && (listParameters.size() == PARAMETER_COUNT) && (SchemaDataType.STRING.equals(listParameters.get(0).getInputDataType().getDataTypeName()))) { final String strURLInput; final int intStatus; final String strResponseBody; strURLInput = listParameters.get(0).getValue(); // Use the default URL if the Parameter was blank if ((strURLInput != null) && (!EMPTY_STRING.equals(strURLInput.trim()))) { method = new GetMethod(strURLInput); } // See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html // The User-Agent request-header field contains information about the user agent originating the request method.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)"); // The Referer[sic] request-header field allows the client to specify, for the server's benefit, // the address (URI) of the resource from which the Request-URI was obtained // (the "referrer", although the header field is misspelled.) method.setRequestHeader("Referer", strReferrerURL); SimpleEventLogUIComponent.logEvent(getEventLogFragment(), EventStatus.INFO, METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_HTTP + METADATA_URL_REQUEST + strURLInput + TERMINATOR + SPACE + METADATA_URL_REFERRER + strReferrerURL + TERMINATOR, SOURCE, getObservatoryClock()); // Now try to send the Request intStatus = client.executeMethod(method); // Check the server status if (intStatus != HttpStatus.SC_OK) { SimpleEventLogUIComponent .logEvent(getEventLogFragment(), EventStatus.WARNING, METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_HTTP + METADATA_MESSAGE + ERROR_HTTP + method.getStatusLine() + TERMINATOR, SOURCE, getObservatoryClock()); } // It is vital that the response body is *always* read, // regardless of the status returned by the server. strResponseBody = method.getResponseBodyAsString(); if ((strResponseBody != null) && (getRawData() != null)) { final Vector vecResponseBody; // If we get here, it must have succeeded... // Add one channel of data, the Response // There must be one Calendar and ChannelCount samples in the Vector... vecResponseBody = new Vector(2); vecResponseBody.add(getObservatoryClock().getCalendarDateNow()); vecResponseBody.add(strResponseBody); getRawData().add(vecResponseBody); setRawDataChannelCount(CHANNEL_COUNT); setTemperatureChannel(false); // Create the ResponseMessage // The ResponseValue is just 'Ok' commandType.getResponse().setValue(ResponseMessageStatus.SUCCESS.getResponseValue()); responseMessage = ResponseMessageHelper.constructSuccessfulResponse(this, commandmessage, commandType); } else { // No data are available SimpleEventLogUIComponent.logEvent(getEventLogFragment(), EventStatus.WARNING, METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_HTTP + METADATA_MESSAGE + ERROR_PARSE_DATA + TERMINATOR, SOURCE, getObservatoryClock()); } } else { throw new NumberFormatException(ResponseMessageStatus.INVALID_PARAMETER.getName()); } } catch (NumberFormatException exception) { // Invalid Parameters SimpleEventLogUIComponent.logEvent(getEventLogFragment(), EventStatus.FATAL, METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_HTTP + METADATA_EXCEPTION + ERROR_PARSE_INPUT + TERMINATOR + SPACE + METADATA_MESSAGE + exception.getMessage() + TERMINATOR, SOURCE, getObservatoryClock()); } catch (IllegalArgumentException exception) { SimpleEventLogUIComponent.logEvent(getEventLogFragment(), EventStatus.FATAL, METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_HTTP + METADATA_EXCEPTION + ERROR_PARSE_INPUT + TERMINATOR + SPACE + METADATA_MESSAGE + exception.getMessage() + TERMINATOR, SOURCE, getObservatoryClock()); } catch (HttpException exception) { SimpleEventLogUIComponent.logEvent(getEventLogFragment(), EventStatus.WARNING, METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_HTTP + METADATA_EXCEPTION + ERROR_HTTP + TERMINATOR + SPACE + METADATA_MESSAGE + exception.getMessage() + TERMINATOR, SOURCE, getObservatoryClock()); } catch (IOException exception) { SimpleEventLogUIComponent.logEvent(getEventLogFragment(), EventStatus.WARNING, METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_HTTP + METADATA_EXCEPTION + ERROR_IO + TERMINATOR + SPACE + METADATA_MESSAGE + exception.getMessage() + TERMINATOR, SOURCE, getObservatoryClock()); } finally { method.releaseConnection(); } // If the Command failed, do not change any DAO data containers! // Our valuable data must remain available for export later... responseMessage = ResponseMessageHelper.constructFailedResponseIfNull(this, commandmessage, commandType, responseMessage); return (responseMessage); }
From source file:org.kalypso.ui.rrm.internal.newproject.ImportRrmInitialDataOperation.java
private void mapRiver(final List<?> sourceFeatureList, final Map<IValuePropertyType, IValuePropertyType> mapping) { final NaModell naModell = (NaModell) m_modelWS.getRootFeature(); // find column for id final IValuePropertyType idColKey = findColumnForId(mapping); // StrangArt is defined in dummyFeatureType (member variable) final IValuePropertyType typeKey = findColumn(mapping, KalypsoNAProjectWizard.QNAME_STRANGART); //$NON-NLS-1$ // remove the channel type mapping (just needed once) removeColumn(mapping, KalypsoNAProjectWizard.QNAME_STRANGART); final IFeatureBindingCollection<Channel> channels = naModell.getChannels(); for (final Object sourceElement : sourceFeatureList) { final Feature sourceFeature = (Feature) sourceElement; final Object o = sourceFeature.getProperty(typeKey); int channelType = 0; try {// ww w. j a v a2 s . c om channelType = ((Integer) SpecialPropertyMapper.map(o.getClass(), Integer.class, o)).intValue(); } catch (final Exception e) { e.printStackTrace(); throw new NumberFormatException(Messages.getString("KalypsoNAProjectWizard.ExceptionStrangArt")); //$NON-NLS-1$ } final String fid = getId(idColKey, sourceFeature, "S"); //$NON-NLS-1$ final Feature targetFeature = createFeatureForChannelType(channelType, channels, fid); copyValues(sourceFeature, targetFeature, mapping, GEO_MAPPING_MULTICURVE_2_CURVE); } }
From source file:com.kdmanalytics.toif.assimilator.XMLNode.java
/** * Parses the string argument as a signed decimal integer. Faster than Integer.parseInt since it * assumes radix 10/*from w w w.j a v a2s .c o m*/ * * @param intString * a String containing the int representation to be parsed * * @return the integer value represented by the argument in decimal. */ public static int parseIntChecked(final String intString) { // Ensure that we have checkNotNull(intString, "A null string cannot be parsed"); // Check for a sign. int num = 0; int sign = -1; final int len = intString.length(); final char ch = intString.charAt(0); if (ch == '-') { if (len == 1) { throw new NumberFormatException("Missing digits: " + intString); } sign = 1; } else { final int d = ch - '0'; if ((d < 0) || (d > 9)) { throw new NumberFormatException("Malformed: " + intString); } num = -d; } // Build the number. final int max = (sign == -1) ? -Integer.MAX_VALUE : Integer.MIN_VALUE; final int multmax = max / 10; int i = 1; while (i < len) { final int d = intString.charAt(i++) - '0'; if ((d < 0) || (d > 9)) { throw new NumberFormatException("Malformed: " + intString); } if (num < multmax) { throw new NumberFormatException("Over/underflow: " + intString); } num *= 10; if (num < (max + d)) { throw new NumberFormatException("Over/underflow: " + intString); } num -= d; } return sign * num; }
From source file:op.tools.SYSCalendar.java
/** * erkennt Uhrzeiten im Format HH:MM und erstellt einen GregorianCalendar basierend auf ref *///ww w.ja v a 2 s. c o m public static GregorianCalendar parseTime(String input, GregorianCalendar gc) throws NumberFormatException { if (input == null || input.equals("")) { throw new NumberFormatException("leere Eingabe"); } StringTokenizer st = new StringTokenizer(input, ":,."); if (st.countTokens() > 3) { throw new NumberFormatException("falsches Format"); } String sStunde = "00"; String sMinute = "00"; String sSekunde = "00"; if (st.countTokens() == 1) { // maybe a simple hour sStunde = st.nextToken(); } else if (st.countTokens() == 2) { // maybe a simple hour sStunde = st.nextToken(); sMinute = st.nextToken(); } else { sStunde = st.nextToken(); sMinute = st.nextToken(); sSekunde = st.nextToken(); } int stunde, minute, sekunde; GregorianCalendar now = (GregorianCalendar) gc.clone(); try { stunde = Integer.parseInt(sStunde); } catch (NumberFormatException nfe) { throw new NumberFormatException("stunde"); } try { minute = Integer.parseInt(sMinute); } catch (NumberFormatException nfe) { throw new NumberFormatException("minute"); } try { sekunde = Integer.parseInt(sSekunde); } catch (NumberFormatException nfe) { throw new NumberFormatException("Sekunde"); } if (stunde < 0) { throw new NumberFormatException("stunde"); } if (stunde > 23) { throw new NumberFormatException("stunde"); } if (minute < 0 || minute > 59) { throw new NumberFormatException("minute"); } if (sekunde < 0 || sekunde > 59) { throw new NumberFormatException("Sekunde"); } now.set(GregorianCalendar.HOUR_OF_DAY, stunde); now.set(GregorianCalendar.MINUTE, minute); now.set(GregorianCalendar.SECOND, sekunde); return now; }
From source file:mondrian.spi.impl.JdbcDialectImpl.java
public void quoteBooleanLiteral(StringBuilder buf, String value) { // NOTE jvs 1-Jan-2007: See quoteDateLiteral for explanation. // In addition, note that we leave out UNKNOWN (even though // it is a valid SQL:2003 literal) because it's really // NULL in disguise, and NULL is always treated specially. if (!value.equalsIgnoreCase("TRUE") && !(value.equalsIgnoreCase("FALSE"))) { throw new NumberFormatException("Illegal BOOLEAN literal: " + value); }//from w w w .jav a 2s . c o m buf.append(value); }
From source file:net.starschema.clouddb.jdbc.ScrollableResultset.java
/** {@inheritDoc} */ @Override//w w w. ja v a 2 s . co m public BigDecimal getBigDecimal(int columnIndex) throws SQLException { String coltype = this.getMetaData().getColumnTypeName(columnIndex); if (coltype.equals("STRING")) { String Value = this.getString(columnIndex); if (this.wasNull()) { return null; } else { try { return new java.math.BigDecimal(Value); } catch (NumberFormatException e) { throw new BQSQLException(e); } } } else if (coltype.equals("INTEGER")) { int Value = this.getInt(columnIndex); if (this.wasNull()) { return null; } else { return new java.math.BigDecimal(Value); } } else if (coltype.equals("FLOAT")) { Float Value = this.getFloat(columnIndex); if (this.wasNull()) { return null; } else { return new java.math.BigDecimal(Value); } } else if (coltype.equals("BOOLEAN")) { throw new NumberFormatException("Cannot format Boolean to BigDecimal"); } else { throw new NumberFormatException("Undefined format"); } }
From source file:org.ardverk.daap.DaapUtil.java
private static int parseHexToInt(int hex) { switch (hex) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'A': return 10; case 'a': return 10; case 'B': return 11; case 'b': return 11; case 'C': return 12; case 'c': return 12; case 'D': return 13; case 'd': return 13; case 'E': return 14; case 'e': return 14; case 'F': return 15; case 'f': return 15; default:/*w ww . j a v a2s . co m*/ throw new NumberFormatException("'" + Character.toString((char) hex) + "'"); } }
From source file:burstcoin.observer.service.ATService.java
public static byte[] parseHexString(String hex) { byte[] bytes = new byte[hex.length() / 2]; for (int i = 0; i < bytes.length; i++) { int char1 = hex.charAt(i * 2); char1 = char1 > 0x60 ? char1 - 0x57 : char1 - 0x30; int char2 = hex.charAt(i * 2 + 1); char2 = char2 > 0x60 ? char2 - 0x57 : char2 - 0x30; if (char1 < 0 || char2 < 0 || char1 > 15 || char2 > 15) { throw new NumberFormatException("Invalid hex number: " + hex); }//from www .j a v a 2 s . c o m bytes[i] = (byte) ((char1 << 4) + char2); } return bytes; }
From source file:org.sakaiproject.citation.impl.BaseConfigurationService.java
/** * Get the maximum number of databases we can search at one time * @return The maximum value (defaults to <code>SEARCHABLE_DATABASES</code> * if no other value is specified) *//*from w w w. j a v a 2s . co m*/ public synchronized int getSiteConfigMaximumSearchableDBs() { String configValue = getConfigurationParameter("searchable-databases"); int searchableDbs = SEARCHABLE_DATABASES; /* * Supply the default if no value was configured */ if (configValue == null) { return searchableDbs; } /* * Make sure we have a good value */ try { searchableDbs = Integer.parseInt(configValue); if (searchableDbs <= 0) { throw new NumberFormatException(configValue); } } catch (NumberFormatException exception) { if (m_log.isDebugEnabled()) { m_log.debug("Maximum searchable database exception: " + exception.toString()); } searchableDbs = SEARCHABLE_DATABASES; } finally { return searchableDbs; } }