static int readInt(BufferedSource source) throws IOException { try { long result = source.readDecimalLong(); String line = source.readUtf8LineStrict(); if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) { throw new IOException("expected an int but was \"" + result + line + "\""); } return (int) result; } catch (NumberFormatException e) { throw new IOException(e.getMessage()); } }
private <T extends Number> T assertConvertible( Supplier<T> func ) { try { return func.get(); } catch ( NumberFormatException e ) { throw new InvalidValuesArgumentException( e.getMessage(), e ); } }
private static Integer getClientPortFromChannel(Channel channel) { String address = getAddressFromChannel(channel); Integer port = 0; try { if (address.contains(Constants.IP_PORT_SPLIT_CHAR)) { port = Integer.parseInt(address.substring(address.lastIndexOf(Constants.IP_PORT_SPLIT_CHAR) + 1)); } } catch (NumberFormatException exx) { LOGGER.error(exx.getMessage()); } return port; }
private static Integer getClientPortFromChannel(Channel channel) { String address = getAddressFromChannel(channel); Integer port = 0; try { if (address.contains(Constants.IP_PORT_SPLIT_CHAR)) { port = Integer.parseInt(address.substring(address.lastIndexOf(Constants.IP_PORT_SPLIT_CHAR) + 1)); } } catch (NumberFormatException exx) { LOGGER.error(exx.getMessage()); } return port; }
static int readInt(BufferedSource source) throws IOException { try { long result = source.readDecimalLong(); String line = source.readUtf8LineStrict(); if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) { throw new IOException("expected an int but was \"" + result + line + "\""); } return (int) result; } catch (NumberFormatException e) { throw new IOException(e.getMessage()); } }
/** * Effective value as {@code int}. * @return the value as {@code int}. If the property does not have value nor default value, then {@code empty} is returned. * @throws NumberFormatException if value is not empty and is not a parsable integer */ default Optional<Integer> getInt(String key) { try { return get(key).map(String::trim).map(Integer::parseInt); } catch (NumberFormatException e) { throw new IllegalStateException(String.format("The property '%s' is not an int value: %s", key, e.getMessage())); } }
/** * Effective value as {@code long}. * @return the value as {@code long}. If the property does not have value nor default value, then {@code empty} is returned. * @throws NumberFormatException if value is not empty and is not a parsable {@code long} */ default Optional<Long> getLong(String key) { try { return get(key).map(String::trim).map(Long::parseLong); } catch (NumberFormatException e) { throw new IllegalStateException(String.format("The property '%s' is not an long value: %s", key, e.getMessage())); } }
/** * Effective value as {@code Float}. * @return the value as {@code Float}. If the property does not have value nor default value, then {@code empty} is returned. * @throws NumberFormatException if value is not empty and is not a parsable number */ default Optional<Float> getFloat(String key) { try { return get(key).map(String::trim).map(Float::valueOf); } catch (NumberFormatException e) { throw new IllegalStateException(String.format("The property '%s' is not an float value: %s", key, e.getMessage())); } }
/** * Effective value as {@code Double}. * @return the value as {@code Double}. If the property does not have value nor default value, then {@code empty} is returned. * @throws NumberFormatException if value is not empty and is not a parsable number */ default Optional<Double> getDouble(String key) { try { return get(key).map(String::trim).map(Double::valueOf); } catch (NumberFormatException e) { throw new IllegalStateException(String.format("The property '%s' is not an double value: %s", key, e.getMessage())); } }
private int allowableClockSkewMs() { String allowableClockSkewMsValue = option(ALLOWABLE_CLOCK_SKEW_MILLIS_OPTION); int allowableClockSkewMs = 0; try { allowableClockSkewMs = allowableClockSkewMsValue == null || allowableClockSkewMsValue.trim().isEmpty() ? 0 : Integer.parseInt(allowableClockSkewMsValue.trim()); } catch (NumberFormatException e) { throw new OAuthBearerConfigException(e.getMessage(), e); } if (allowableClockSkewMs < 0) { throw new OAuthBearerConfigException( String.format("Allowable clock skew millis must not be negative: %s", allowableClockSkewMsValue)); } return allowableClockSkewMs; }
static int readInt(BufferedSource source) throws IOException { try { long result = source.readDecimalLong(); String line = source.readUtf8LineStrict(); if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) { throw new IOException("expected an int but was \"" + result + line + "\""); } return (int) result; } catch (NumberFormatException e) { throw new IOException(e.getMessage()); } }
@Override public String getConnectionTestReport( DatabaseMeta databaseMeta ) { try { OpenERPHelper helper = new OpenERPHelper( databaseMeta ); helper.StartSession(); return "Successfully connected to [" + databaseMeta.environmentSubstitute( databaseMeta.getName() ) + "]"; } catch ( NumberFormatException e ) { return "Invalid port number: " + e.getMessage(); } catch ( Exception e ) { return "Connection failed: " + e.getMessage(); } }
private void readChunkSize() throws IOException { // Read the suffix of the previous chunk. if (bytesRemainingInChunk != NO_CHUNK_YET) { source.readUtf8LineStrict(); } try { bytesRemainingInChunk = source.readHexadecimalUnsignedLong(); String extensions = source.readUtf8LineStrict().trim(); if (bytesRemainingInChunk < 0 || (!extensions.isEmpty() && !extensions.startsWith(";"))) { throw new ProtocolException("expected chunk size and optional extensions but was \"" + bytesRemainingInChunk + extensions + "\""); } } catch (NumberFormatException e) { throw new ProtocolException(e.getMessage()); } if (bytesRemainingInChunk == 0L) { hasMoreChunks = false; trailers = readHeaders(); HttpHeaders.receiveHeaders(client.cookieJar(), url, trailers); endOfInput(true, null); } }
public final Number decimalValue(boolean decimal) { char chLocal = charAt(np + sp - 1); try { if (chLocal == 'F') { return Float.parseFloat(numberString()); } if (chLocal == 'D') { return Double.parseDouble(numberString()); } if (decimal) { return decimalValue(); } else { return doubleValue(); } } catch (NumberFormatException ex) { throw new JSONException(ex.getMessage() + ", " + info()); } }
@Test public void longDecimalStringTooLowThrows() throws IOException { try { sink.writeUtf8("-9223372036854775809"); // Right size but cannot fit. sink.emit(); source.readDecimalLong(); fail(); } catch (NumberFormatException e) { assertEquals("Number too large: -9223372036854775809", e.getMessage()); } }
@Test public void longHexStringTooLongThrows() throws IOException { try { sink.writeUtf8("fffffffffffffffff"); sink.emit(); source.readHexadecimalUnsignedLong(); fail(); } catch (NumberFormatException e) { assertEquals("Number too large: fffffffffffffffff", e.getMessage()); } }
@Test public void longDecimalStringTooLongThrows() throws IOException { try { sink.writeUtf8("12345678901234567890"); // Too many digits. sink.emit(); source.readDecimalLong(); fail(); } catch (NumberFormatException e) { assertEquals("Number too large: 12345678901234567890", e.getMessage()); } }
@Test public void longDecimalStringTooShortThrows() throws IOException { try { sink.writeUtf8(" "); sink.emit(); source.readDecimalLong(); fail(); } catch (NumberFormatException e) { assertEquals("Expected leading [0-9] or '-' character but was 0x20", e.getMessage()); } }
@Test public void longHexStringTooShortThrows() throws IOException { try { sink.writeUtf8(" "); sink.emit(); source.readHexadecimalUnsignedLong(); fail(); } catch (NumberFormatException e) { assertEquals("Expected leading [0-9a-fA-F] character but was 0x20", e.getMessage()); } }
@Test public void longDecimalStringTooHighThrows() throws IOException { try { sink.writeUtf8("9223372036854775808"); // Right size but cannot fit. sink.emit(); source.readDecimalLong(); fail(); } catch (NumberFormatException e) { assertEquals("Number too large: 9223372036854775808", e.getMessage()); } }