@Override public long contentLength() { try { return contentLength != null ? Long.parseLong(contentLength) : -1; } catch (NumberFormatException e) { return -1; } }
private static long stringToLong(String s) { if (s == null) return -1; try { return Long.parseLong(s); } catch (NumberFormatException e) { return -1; } }
private static long stringToLong(String s) { if (s == null) return -1; try { return Long.parseLong(s); } catch (NumberFormatException e) { return -1; } } }
Long.parseLong("0", 10) // returns 0L Long.parseLong("473", 10) // returns 473L Long.parseLong("-0", 10) // returns 0L Long.parseLong("-FF", 16) // returns -255L Long.parseLong("1100110", 2) // returns 102L Long.parseLong("99", 8) // throws a NumberFormatException Long.parseLong("Hazelnut", 10) // throws a NumberFormatException Long.parseLong("Hazelnut", 36) // returns 1356099454469L Long.parseLong("999") // returns 999L
@Override public void onMessage(WebSocket webSocket, String text) { countRef.set(Long.parseLong(text)); }
@Nullable private Long headerToLong(@Nullable Object headerValue) { if (headerValue instanceof Number) { return ((Number) headerValue).longValue(); } else if (headerValue instanceof String) { return Long.parseLong((String) headerValue); } else { return null; } }
@Override public void parse(CacheBuilderSpec spec, String key, String value) { checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key); try { parseLong(spec, Long.parseLong(value)); } catch (NumberFormatException e) { throw new IllegalArgumentException( format("key %s value set to %s, must be integer", key, value), e); } } }
/** * Return the content-length header or -1 if unknown. */ public long getContentLength() { String value = getFirst(CONTENT_LENGTH); return (value != null ? Long.parseLong(value) : -1); }
@Nullable public Long getTimestamp() { Object value = getHeader(MessageHeaders.TIMESTAMP); if (value == null) { return null; } return (value instanceof Long ? (Long) value : Long.parseLong(value.toString())); }
/** * Return the length of the body in bytes, as specified by the * {@code Content-Length} header. * <p>Returns -1 when the content-length is unknown. */ public long getContentLength() { String value = getFirst(CONTENT_LENGTH); return (value != null ? Long.parseLong(value) : -1); }
/** * Return the value of the {@code Access-Control-Max-Age} response header. * <p>Returns -1 when the max age is unknown. */ public long getAccessControlMaxAge() { String value = getFirst(ACCESS_CONTROL_MAX_AGE); return (value != null ? Long.parseLong(value) : -1); }
private static long parseDelayAsLong(String value) throws RuntimeException { if (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))) { return Duration.parse(value).toMillis(); } return Long.parseLong(value); }
@Override public Object fromMessage(javax.jms.Message message) throws JMSException, MessageConversionException { if (this.called) { throw new java.lang.IllegalStateException("Converter called twice"); } this.called = true; TextMessage textMessage = (TextMessage) message; return Long.parseLong(textMessage.getText()); } }
/** Set lengths using decimal numbers like "10123". */ void setLengths(String[] strings) throws IOException { if (strings.length != valueCount) { throw invalidLengths(strings); } try { for (int i = 0; i < strings.length; i++) { lengths[i] = Long.parseLong(strings[i]); } } catch (NumberFormatException e) { throw invalidLengths(strings); } }
public long getParameter(String key, long defaultValue) { Number n = getNumbers().get(key); if (n != null) { return n.longValue(); } String value = getParameter(key); if (StringUtils.isEmpty(value)) { return defaultValue; } long l = Long.parseLong(value); getNumbers().put(key, l); return l; }
public long getParameter(String key, long defaultValue) { Number n = getNumbers().get(key); if (n != null) { return n.longValue(); } String value = getParameter(key); if (StringUtils.isEmpty(value)) { return defaultValue; } long l = Long.parseLong(value); getNumbers().put(key, l); return l; }
/** * Computes the mean in a way that is obvious and resilient to overflow by using BigInteger * arithmetic. */ private static long computeMeanSafely(long x, long y) { BigInteger bigX = BigInteger.valueOf(x); BigInteger bigY = BigInteger.valueOf(y); BigDecimal bigMean = new BigDecimal(bigX.add(bigY)).divide(BigDecimal.valueOf(2), BigDecimal.ROUND_FLOOR); // parseInt blows up on overflow as opposed to intValue() which does not. return Long.parseLong(bigMean.toString()); }
public static Literal getLongLiteral(String numberToken, int startPos, int endPos, int radix) { try { long value = Long.parseLong(numberToken, radix); return new LongLiteral(numberToken, startPos, endPos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_LONG, numberToken)); } }
private void parseRetry(long end) throws IOException { end -= skipNameAndDivider(5L); String retryString = source.readUtf8(end); long retryMs = -1L; try { retryMs = Long.parseLong(retryString); } catch (NumberFormatException ignored) { } if (retryMs != -1L) { callback.onRetryChange(retryMs); } skipCrAndOrLf(); }
public static SpecialRandom valueOf(String s) { return (s.length() == 0) ? new SpecialRandom() : new SpecialRandom(Long.parseLong(s)); }