Parses an unsigned long from the specified sub array of bytes. @param b the bytes to parse @param off the start offset of the bytes @param len the length of the bytes @return the long value @exception NumberFormatException if the long format was invalid
(byte[] b, int off, int len)
| 89 | * @exception NumberFormatException if the long format was invalid |
| 90 | */ |
| 91 | public static long parseLong(byte[] b, int off, int len) throws NumberFormatException { |
| 92 | int c; |
| 93 | |
| 94 | if (b == null || len <= 0 || !isDigit(c = b[off++])) { |
| 95 | throw new NumberFormatException(); |
| 96 | } |
| 97 | |
| 98 | long n = c - '0'; |
| 99 | while (--len > 0) { |
| 100 | if (isDigit(c = b[off++]) && (n < OVERFLOW_LIMIT || (n == OVERFLOW_LIMIT && (c - '0') < 8))) { |
| 101 | n = n * 10 + c - '0'; |
| 102 | } else { |
| 103 | throw new NumberFormatException(); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return n; |
| 108 | } |
| 109 | } |