将16进制的String转化为Long

当str为空或非数字字符串时抛NumberFormatException
774028
public static Long hexToLongObject(@NotNull String str) {
		// 统一行为，不要有时候抛NPE，有时候抛NumberFormatException
		if (str == null) {
			throw new NumberFormatException("null");
		}
		return Long.decode(str);
	}
1010716
public static Integer stringToInteger(String strString) throws Exception
    {
        Number objData;
        initGlobals();      // Make sure you have the utilities
        if ((strString == null) || (strString.equals(Constant.BLANK)))
            return null;
        strString = DataConverters.stripNonNumber(strString);
        try   {
            synchronized (gIntegerFormat)
            {
                objData = gIntegerFormat.parse(strString);
            }
            if (!(objData instanceof Integer))
            {
                if (objData instanceof Number)
                    objData = new Integer(objData.intValue());
                else
                    objData = null;
            }
        } catch (ParseException ex)   {
            objData = null;
        }
        if (objData == null)
            if (strString != null)
            if (strString.length() > 0)
        {
            try   {
                objData = new Integer(strString);
            } catch (NumberFormatException ex)  {
                throw ex;
            }
        }
        return (Integer)objData;
    }
285972
public long parseDate(String string) throws Exception
  {
    try {
      int strlen = string.length();

      if (strlen == 0)
        return 0;

      int i = skipWhitespace(string, strlen, 0);

      int ch = string.charAt(i);
      if (ch >= '0' && ch <= '9'
          || (ch == 'T' && i + 1 < strlen
              && string.charAt(i + 1) >= '0' && string.charAt(i + 1) <= '9'))
        return parseISO8601Date(string, i);

      CharBuffer cb = new CharBuffer();

      i = scan(string, 0, cb, true);
      if (cb.length() == 0 || ! Character.isDigit(cb.charAt(0)))
        i = scan(string, i, cb, true);

      int dayOfMonth = parseInt(cb);
      i = scan(string, i, cb, true);
      String smonth = cb.toString();
      int month;
      for (month = 0; month < 12; month++) {
        if (MONTH_NAMES[(int) month].equalsIgnoreCase(smonth))
          break;
      }

      if (month == 12)
        throw new Exception("Unexpected month: " + month);

      i = scan(string, i, cb, true);

      int year = parseInt(cb);
      if (cb.length() < 3 && year < 50)
        year += 2000;
      else if (cb.length() < 3 && year < 100)
        year += 1900;

      i = scan(string, i, cb, false);
      long timeOfDay = parseInt(cb) * 3600000;

      i = scan(string, i, cb, false);
      timeOfDay += parseInt(cb) * 60000;

      i = scan(string, i, cb, false);
      timeOfDay += parseInt(cb) * 1000;

      // XXX: gross hack
      if (year <= 1600)
        dayOfMonth--;

      long time = (MS_PER_DAY * (yearToDayOfEpoch(year)
                                 + monthToDayOfYear(month, isLeapYear(year))
                                 + dayOfMonth - 1)
                   + timeOfDay);

      try {
        i = scan(string, i, cb, false);
        for (int j = 0; j < cb.length(); j++) {
          if ((ch = cb.charAt(j)) == ';' || ch == ' ')
            cb.length(j);
        }

        ch = cb.length() > 0 ? cb.charAt(0) : 0;
        if (ch == '-' || ch == '+' || ch >= '0' && ch <= '9') {
          long zoneOffset;
          zoneOffset = parseInt(cb);
          zoneOffset = 60000 * (60 * (zoneOffset / 100) + zoneOffset % 100);

          time -= zoneOffset;

          setGMTTime(time);
        } else if (cb.equalsIgnoreCase("gmt") ||
                   cb.equalsIgnoreCase("utc")) {
          setGMTTime(time);
        } else {
          setLocalTime(time);
        }
      } catch (Exception e) {
        log.log(Level.FINER, e.toString(), e);
      }

      return _localTimeOfEpoch - _zoneOffset;
    } catch (Exception e) {
      log.log(Level.FINER, e.toString(), e);

      return Long.MAX_VALUE;
    }
  }
155580
private static String getLongString(ByteBuffer buffer)
    {
        long len = getUnsignedInt(buffer);
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < len; i++)
        {
            builder.append((char)(buffer.get() & 0xff));
        }
        String s = builder.toString();
        return s;
    }
117535
public int setString(long pos, String str) throws SQLException {
    int bytePosition = utf8Position((int) pos - 1);
    super.setBytes(bytePosition + 1 - offset, str.getBytes(StandardCharsets.UTF_8));
    return str.length();
  }
895970
private int getIntValue(String str, int defaultValue) {

        try {
            int intValue = Integer.parseInt(str);
            return (intValue > 0) ? intValue : defaultValue;
        } catch (NumberFormatException e) {
            // intentionally left blank
        }
        return defaultValue;
    }
774266
public static Object stringToValue(String string) {
		if (string.equals("")) {
			return string;
		}
		if (string.equalsIgnoreCase("true")) {
			return Boolean.TRUE;
		}
		if (string.equalsIgnoreCase("false")) {
			return Boolean.FALSE;
		}
		if (string.equalsIgnoreCase("null")) {
			return JSONObject.NULL;
		}

		/*
		 * If it might be a number, try converting it. If a number cannot be
		 * produced, then the value will just be a string.
		 */

		char initial = string.charAt(0);
		if ((initial >= '0' && initial <= '9') || initial == '-') {
			try {
				if (string.indexOf('.') > -1 || string.indexOf('e') > -1
						|| string.indexOf('E') > -1
						|| "-0".equals(string)) {
					Double d = Double.valueOf(string);
					if (!d.isInfinite() && !d.isNaN()) {
						return d;
					}
				} else {
					Long myLong = new Long(string);
					if (string.equals(myLong.toString())) {
						if (myLong.longValue() == myLong.intValue()) {
							return Integer.valueOf(myLong.intValue());
						}
						return myLong;
					}
				}
			} catch (Exception ignore) {}
		}
		return string;
	}
1263150
private boolean isLong(final String str) {
		try {
			Long.valueOf(str);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}
675603
public static final long resolveUnit(String string) throws NumberFormatException {
		if (string == null || "null".equals(string)) {
			return 0l;
		}
		StringBuffer buffer = new StringBuffer(string.toLowerCase());

		// eg. 1KByte -> 1024byte
		long unit = resolveUnit(buffer);
		String number = buffer.toString().trim();
		number = number.replace(',', '.');
		int i = number.indexOf('.');
		if (i > -1) {
			number = number.substring(0, i);
		}
		if (number.length() == 0) {
			return 0;
		}
		long value = Long.parseLong(number);
		if (unit != 1) {
			value *= unit;
		}
		return value;
	}
779877
public static UByte ubyte(String value) throws NumberFormatException {
        return value == null ? null : UByte.valueOf(value);
    }
454162
public static UByte valueOf(String value) throws NumberFormatException {
        return valueOfUnchecked(rangeCheck(Short.parseShort(value)));
    }
873178
public static final Function<BigDecimal,String> toStr() {
	    return (Function<BigDecimal,String>)((Function)FnNumber.toStr());
    }
611509
public final long fromBitString2Long(String str) {
        if (str.length() > 64)
            throw new UnsupportedOperationException("Strings needs to fit into a 'long' but length was " + str.length());

        long res = 0;
        int strLen = str.length();
        for (int charIndex = 0; charIndex < strLen; charIndex++) {
            res <<= 1;
            if (str.charAt(charIndex) != '0')
                res |= 1;
        }
        res <<= (64 - strLen);
        return res;
    }
507427
public static Number toNumber(String str, Number defaultValue) {
	try {
	    // float
	    if (str.indexOf('.') != -1) {
		return new BigDecimal(str);
	    }
	    // integer
	    BigInteger bi = new BigInteger(str);
	    int l = bi.bitLength();
	    if (l < 32) return new Integer(bi.intValue());
	    if (l < 64) return new Long(bi.longValue());
	    return bi;
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    return defaultValue;
	}
    }
1079231
Long getLongAttribute(org.w3c.dom.Node attribute) throws InvalidInputException {
    String s = getStringAttribute(attribute);

    if (s == null) {
      return null;
    }

    try {
      return Long.parseLong(s);
    } catch (NumberFormatException e) {
      throw new InvalidInputException("Invalid input: " + attribute.getNodeName()
          + " must be a int64 value not \"" + s + "\"");
    }
  }
486419
public static Integer hexToIntObject(@NotNull String str) {
		// 统一行为，不要有时候抛NPE，有时候抛NumberFormatException
		if (str == null) {
			throw new NumberFormatException("null");
		}
		return Integer.decode(str);
	}
475252
public static long getLong(String pStr) {
        if (isEmpty(pStr)) {
            return 0;
        }
        long value = 0;
        try {
            value = Long.parseLong(pStr);
        } catch (NumberFormatException nm) {
        }
        return value;
    }