java.lang.NumberFormatException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中java.lang.NumberFormatException.<init>()方法的一些代码示例,展示了NumberFormatException.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NumberFormatException.<init>()方法的具体详情如下:
包路径:java.lang.NumberFormatException
类名称:NumberFormatException
方法名:<init>

NumberFormatException.<init>介绍

[英]Constructs a new NumberFormatException that includes the current stack trace.
[中]构造包含当前堆栈跟踪的新NumberFormatException。

代码示例

代码示例来源:origin: perwendel/spark

/**
 * @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;
}

代码示例来源:origin: perwendel/spark

/**
 * @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;
}

代码示例来源:origin: google/guava

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;
}

代码示例来源:origin: prestodb/presto

private static NumberFormatException _badBD(String s) {
    return new NumberFormatException("Value \""+s+"\" can not be represented as BigDecimal");
  }
}

代码示例来源:origin: redisson/redisson

private static NumberFormatException _badBD(String s) {
    return new NumberFormatException("Value \""+s+"\" can not be represented as BigDecimal");
  }
}

代码示例来源:origin: neo4j/neo4j

private static int digit( char ch )
{
  int digit = ch - '0';
  if ( (digit < 0) || (digit > 9) )
  {
    throw new NumberFormatException();
  }
  return digit;
}

代码示例来源:origin: google/guava

private static byte parseOctet(String ipPart) {
 // Note: we already verified that this string contains only hex digits.
 int octet = Integer.parseInt(ipPart);
 // Disallow leading zeroes, because no clear standard exists on
 // whether these should be interpreted as decimal or octal.
 if (octet > 255 || (ipPart.startsWith("0") && ipPart.length() > 1)) {
  throw new NumberFormatException();
 }
 return (byte) octet;
}

代码示例来源:origin: prestodb/presto

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;
}

代码示例来源:origin: prestodb/presto

private static byte parseOctet(String ipPart) {
 // Note: we already verified that this string contains only hex digits.
 int octet = Integer.parseInt(ipPart);
 // Disallow leading zeroes, because no clear standard exists on
 // whether these should be interpreted as decimal or octal.
 if (octet > 255 || (ipPart.startsWith("0") && ipPart.length() > 1)) {
  throw new NumberFormatException();
 }
 return (byte) octet;
}

代码示例来源:origin: google/guava

/**
 * Returns the unsigned {@code int} value represented by a string with the given radix.
 *
 * <p><b>Java 8 users:</b> use {@link Integer#parseUnsignedInt(String, int)} instead.
 *
 * @param string the string containing the unsigned integer representation to be parsed.
 * @param radix the radix to use while parsing {@code s}; must be between {@link
 *     Character#MIN_RADIX} and {@link Character#MAX_RADIX}.
 * @throws NumberFormatException if the string does not contain a valid unsigned {@code int}, or
 *     if supplied radix is invalid.
 * @throws NullPointerException if {@code s} is null (in contrast to {@link
 *     Integer#parseInt(String)})
 */
@CanIgnoreReturnValue
public static int parseUnsignedInt(String string, int radix) {
 checkNotNull(string);
 long result = Long.parseLong(string, radix);
 if ((result & INT_MASK) != result) {
  throw new NumberFormatException(
    "Input " + string + " in base " + radix + " is not in the range of an unsigned integer");
 }
 return (int) result;
}

代码示例来源:origin: google/guava

/**
 * Returns the unsigned {@code byte} value represented by a string with the given radix.
 *
 * @param string the string containing the unsigned {@code byte} representation to be parsed.
 * @param radix the radix to use while parsing {@code string}
 * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} with
 *     the given radix, or if {@code radix} is not between {@link Character#MIN_RADIX} and {@link
 *     Character#MAX_RADIX}.
 * @throws NullPointerException if {@code string} is null (in contrast to {@link
 *     Byte#parseByte(String)})
 * @since 13.0
 */
@Beta
@CanIgnoreReturnValue
public static byte parseUnsignedByte(String string, int radix) {
 int parse = Integer.parseInt(checkNotNull(string), radix);
 // We need to throw a NumberFormatException, so we have to duplicate checkedCast. =(
 if (parse >> Byte.SIZE == 0) {
  return (byte) parse;
 } else {
  throw new NumberFormatException("out of range: " + parse);
 }
}

代码示例来源:origin: google/guava

static ParseRequest fromString(String stringValue) {
  if (stringValue.length() == 0) {
   throw new NumberFormatException("empty string");
  }

  // Handle radix specifier if present
  String rawValue;
  int radix;
  char firstChar = stringValue.charAt(0);
  if (stringValue.startsWith("0x") || stringValue.startsWith("0X")) {
   rawValue = stringValue.substring(2);
   radix = 16;
  } else if (firstChar == '#') {
   rawValue = stringValue.substring(1);
   radix = 16;
  } else if (firstChar == '0' && stringValue.length() > 1) {
   rawValue = stringValue.substring(1);
   radix = 8;
  } else {
   rawValue = stringValue;
   radix = 10;
  }

  return new ParseRequest(rawValue, radix);
 }
}

代码示例来源:origin: netty/netty

public int parseInt(int start, int end, int radix) {
  if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
    throw new NumberFormatException();
  }
  if (start == end) {
    throw new NumberFormatException();
  }
  int i = start;
  boolean negative = byteAt(i) == '-';
  if (negative && ++i == end) {
    throw new NumberFormatException(subSequence(start, end, false).toString());
  }
  return parseInt(i, end, radix, negative);
}

代码示例来源:origin: netty/netty

public long parseLong(int start, int end, int radix) {
  if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
    throw new NumberFormatException();
  }
  if (start == end) {
    throw new NumberFormatException();
  }
  int i = start;
  boolean negative = byteAt(i) == '-';
  if (negative && ++i == end) {
    throw new NumberFormatException(subSequence(start, end, false).toString());
  }
  return parseLong(i, end, radix, negative);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public int getIntHeader(String name) {
  HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name);
  Object value = (header != null ? header.getValue() : null);
  if (value instanceof Number) {
    return ((Number) value).intValue();
  }
  else if (value instanceof String) {
    return Integer.parseInt((String) value);
  }
  else if (value != null) {
    throw new NumberFormatException("Value for header '" + name + "' is not a Number: " + value);
  }
  else {
    return -1;
  }
}

代码示例来源:origin: spring-projects/spring-framework

public void setTouchy(String touchy) throws Exception {
  if (touchy.indexOf('.') != -1) {
    throw new Exception("Can't contain a .");
  }
  if (touchy.indexOf(',') != -1) {
    throw new NumberFormatException("Number format exception: contains a ,");
  }
  this.touchy = touchy;
}

代码示例来源:origin: netty/netty

public short parseShort(int start, int end, int radix) {
  int intValue = parseInt(start, end, radix);
  short result = (short) intValue;
  if (result != intValue) {
    throw new NumberFormatException(subSequence(start, end, false).toString());
  }
  return result;
}

代码示例来源:origin: redisson/redisson

public short parseShort(int start, int end, int radix) {
  int intValue = parseInt(start, end, radix);
  short result = (short) intValue;
  if (result != intValue) {
    throw new NumberFormatException(subSequence(start, end, false).toString());
  }
  return result;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public int getIntHeader(String name) {
  HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name);
  Object value = (header != null ? header.getValue() : null);
  if (value instanceof Number) {
    return ((Number) value).intValue();
  }
  else if (value instanceof String) {
    return Integer.parseInt((String) value);
  }
  else if (value != null) {
    throw new NumberFormatException("Value for header '" + name + "' is not a Number: " + value);
  }
  else {
    return -1;
  }
}

代码示例来源:origin: google/guava

/**
 * 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;
 }
}

相关文章