diff --git a/guava/src/com/google/common/net/HttpHeaders.java b/guava/src/com/google/common/net/HttpHeaders.java index d045eac5754c..4bb6f9fc3681 100644 --- a/guava/src/com/google/common/net/HttpHeaders.java +++ b/guava/src/com/google/common/net/HttpHeaders.java @@ -129,14 +129,14 @@ private HttpHeaders() {} public static final String AGE = "Age"; /** The HTTP Allow header field name. */ public static final String ALLOW = "Allow"; + /** The HTTP Content-Disposition header field name. */ + public static final String CONTENT_DISPOSITION = "Content-Disposition"; /** The HTTP Content-Encoding header field name. */ public static final String CONTENT_ENCODING = "Content-Encoding"; /** The HTTP Content-Language header field name. */ public static final String CONTENT_LANGUAGE = "Content-Language"; /** The HTTP Content-Location header field name. */ public static final String CONTENT_LOCATION = "Content-Location"; - /** The HTTP Content-Disposition header field name. */ - public static final String CONTENT_DISPOSITION = "Content-Disposition"; /** The HTTP Content-MD5 header field name. */ public static final String CONTENT_MD5 = "Content-MD5"; /** The HTTP Content-Range header field name. */ diff --git a/guava/src/com/google/common/primitives/AndroidInteger.java b/guava/src/com/google/common/primitives/AndroidInteger.java new file mode 100644 index 000000000000..4a92c4bd18a8 --- /dev/null +++ b/guava/src/com/google/common/primitives/AndroidInteger.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.common.primitives; + +/** + * Android {@code Integer.java}, stripped down to {@code parseInt} methods. + */ +final class AndroidInteger { + /** + * Parses the specified string as a signed integer value using the specified + * radix. The ASCII character \u002d ('-') is recognized as the minus sign. + * + * @param string + * the string representation of an integer value. + * @param radix + * the radix to use when parsing. + * @return the primitive integer value represented by {@code string} using + * {@code radix}. + * @throws NumberFormatException + * if {@code string} is {@code null} or has a length of zero, + * {@code radix < Character.MIN_RADIX}, + * {@code radix > Character.MAX_RADIX}, or if {@code string} + * can not be parsed as an integer value. + */ + static int parseInt(String string, int radix) throws NumberFormatException { + if (string == null || radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) { + throw new NumberFormatException("unable to parse '"+string+"' as integer"); + } + int length = string.length(), i = 0; + if (length == 0) { + throw new NumberFormatException("unable to parse '"+string+"' as integer"); + } + boolean negative = string.charAt(i) == '-'; + if (negative && ++i == length) { + throw new NumberFormatException("unable to parse '"+string+"' as integer"); + } + + return parse(string, i, radix, negative); + } + + private static int parse(String string, int offset, int radix, boolean negative) + throws NumberFormatException { + int max = Integer.MIN_VALUE / radix; + int result = 0, length = string.length(); + while (offset < length) { + int digit = Character.digit(string.charAt(offset++), radix); + if (digit == -1) { + throw new NumberFormatException("unable to parse '"+string+"' as integer"); + } + if (max > result) { + throw new NumberFormatException("unable to parse '"+string+"' as integer"); + } + int next = result * radix - digit; + if (next > result) { + throw new NumberFormatException("unable to parse '"+string+"' as integer"); + } + result = next; + } + if (!negative) { + result = -result; + if (result < 0) { + throw new NumberFormatException("unable to parse '"+string+"' as integer"); + } + } + return result; + } + + private AndroidInteger() {} +}