/** * @param c An ASCII encoded character 0-9 a-f A-F * @return The byte value of the character 0-16. */ public static int convertHexDigit(char c) { int d = ((c & 0x1f) + ((c >> 6) * 0x19) - 0x10); if (d < 0 || d > 15) { throw new NumberFormatException("!hex " + c); } return d; }
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()); } }
static int parsePortNumber(String portStr) { try { return Integer.parseInt(portStr); } catch (java.lang.NumberFormatException e) { e.printStackTrace(); usage("Could not interpret port number [" + portStr + "]."); // we won't get here return -1; } }
@Override public LongColumn appendCell(final String value) { try { return append(LongColumnType.DEFAULT_PARSER.parseLong(value)); } catch (final NumberFormatException e) { throw new NumberFormatException("Error adding value to column " + name() + ": " + e.getMessage()); } }
/** * Returns the unsigned {@code int} value represented by the given string. * * <p>Accepts a decimal, hexadecimal, or octal number given by specifying the following prefix: * * <ul> * <li>{@code 0x}<i>HexDigits</i> * <li>{@code 0X}<i>HexDigits</i> * <li>{@code #}<i>HexDigits</i> * <li>{@code 0}<i>OctalDigits</i> * </ul> * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @since 13.0 */ @CanIgnoreReturnValue public static int decode(String stringValue) { ParseRequest request = ParseRequest.fromString(stringValue); try { return parseUnsignedInt(request.rawValue, request.radix); } catch (NumberFormatException e) { NumberFormatException decodeException = new NumberFormatException("Error parsing value: " + stringValue); decodeException.initCause(e); throw decodeException; } }
@Override public String validate(String value) { try { float fvalue = Float.parseFloat(value); if (fvalue < 0 || fvalue > 1) { return "Invalid ratio " + value + ", which should be in between 0 to 1"; } } catch (NumberFormatException e) { return e.toString(); } return null; }
@Override public FloatColumn appendCell(final String value, AbstractParser<?> parser) { try { return append(parser.parseFloat(value)); } catch (final NumberFormatException e) { throw new NumberFormatException("Error adding value to column " + name() + ": " + e.getMessage()); } }
/** * Returns the unsigned {@code long} value represented by the given string. * * <p>Accepts a decimal, hexadecimal, or octal number given by specifying the following prefix: * * <ul> * <li>{@code 0x}<i>HexDigits</i> * <li>{@code 0X}<i>HexDigits</i> * <li>{@code #}<i>HexDigits</i> * <li>{@code 0}<i>OctalDigits</i> * </ul> * * @throws NumberFormatException if the string does not contain a valid unsigned {@code long} * value * @since 13.0 */ @CanIgnoreReturnValue public static long decode(String stringValue) { ParseRequest request = ParseRequest.fromString(stringValue); try { return parseUnsignedLong(request.rawValue, request.radix); } catch (NumberFormatException e) { NumberFormatException decodeException = new NumberFormatException("Error parsing value: " + stringValue); decodeException.initCause(e); throw decodeException; } }
/** * @param c An ASCII encoded character 0-9 a-f A-F * @return The byte value of the character 0-16. */ public static int convertHexDigit(int c) { int d = ((c & 0x1f) + ((c >> 6) * 0x19) - 0x10); if (d < 0 || d > 15) { throw new NumberFormatException("!hex " + c); } return d; }
@Override public IntColumn appendCell(final String value) { try { return append(IntColumnType.DEFAULT_PARSER.parseInt(value)); } catch (final NumberFormatException e) { throw new NumberFormatException("Error adding value to column " + name() + ": " + e.getMessage()); } }
private static long parseLong(String arg) { try { return Long.parseLong(arg); } catch (NumberFormatException ex) { throw new IllegalArgumentException( "Could not parse -maxOplogSize=" + arg + " because: " + ex.getMessage()); } }
private long extractContentLength(Map<String, String> header) { long size = 0x7FFFFFFFFFFFFFFFl; String contentLength = header.get("content-length"); if (contentLength != null) { try { size = Integer.parseInt(contentLength); } catch (NumberFormatException ex) { ex.printStackTrace(); } } return size; }
private static short parseHextet(String ipPart) { // Note: we already verified that this string contains only hex digits. int hextet = Integer.parseInt(ipPart, 16); if (hextet > 0xffff) { throw new NumberFormatException(); } return (short) hextet; }
@Override public IntColumn appendCell(final String value, AbstractParser<?> parser) { try { return append(parser.parseInt(value)); } catch (final NumberFormatException e) { throw new NumberFormatException("Error adding value to column " + name() + ": " + 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 void SaveInputPlayBuffer(String bufferText) { try { Integer intValue; intValue = Integer.valueOf(bufferText); playBuffer = intValue; Log.i(TAG, "Input play buffer:" + playBuffer); } catch (NumberFormatException e) { Log.i(TAG, "Input play buffer convert exception"); e.printStackTrace(); } }
private static NumberFormatException _badBD(String s) { return new NumberFormatException("Value \""+s+"\" can not be represented as BigDecimal"); } }
@Override public ShortColumn appendCell(final String value) { try { return append(ShortColumnType.DEFAULT_PARSER.parseShort(value)); } catch (final NumberFormatException e) { throw new NumberFormatException("Error adding value to column " + name() + ": " + e.getMessage()); } }
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 int readAPIVersion (File parentFile) { File propertiesFile = new File(parentFile, "source.properties"); Properties properties; try { properties = readPropertiesFromFile(propertiesFile); String versionString = properties.getProperty("AndroidVersion.ApiLevel"); return Integer.parseInt(versionString); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } return 0; }