diff --git a/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java b/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java index 62bc14ec7..8028d63c6 100644 --- a/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java +++ b/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java @@ -29,7 +29,7 @@ /** * Low-level JSON library implementation based on Jackson 2. * - *

Implementation is thread-safe, and sub-classes must be thread-safe. For maximum efficiency, + *

Implementation is thread-safe. For maximum efficiency, * applications should use a single globally-shared instance of the JSON factory. * * @since 1.11 diff --git a/google-http-client-xml/src/main/java/com/google/api/client/xml/atom/Atom.java b/google-http-client-xml/src/main/java/com/google/api/client/xml/atom/Atom.java index 85b39b0a9..c948bd36d 100644 --- a/google-http-client-xml/src/main/java/com/google/api/client/xml/atom/Atom.java +++ b/google-http-client-xml/src/main/java/com/google/api/client/xml/atom/Atom.java @@ -49,7 +49,7 @@ public final class Atom { /** Escaper for the {@code Slug} header. */ private static final PercentEscaper SLUG_ESCAPER = - new PercentEscaper(" !\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~", false); + new PercentEscaper(" !\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~"); static final class StopAtAtomEntry extends Xml.CustomizeParser { diff --git a/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java b/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java index 45e9d5ab5..3204f695e 100644 --- a/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java +++ b/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java @@ -52,8 +52,7 @@ */ public class GenericUrl extends GenericData { - private static final Escaper URI_FRAGMENT_ESCAPER = - new PercentEscaper("=&-_.!~*'()@:$,;/?:", false); + private static final Escaper URI_FRAGMENT_ESCAPER = new PercentEscaper("=&-_.!~*'()@:$,;/?:"); /** Scheme (lowercase), for example {@code "https"}. */ private String scheme; @@ -90,7 +89,7 @@ public class GenericUrl extends GenericData { public GenericUrl() {} /** - * Constructs from an encoded URL. + * Constructs a GenericUrl from a URL encoded string. * *

Any known query parameters with pre-defined fields as data keys will be parsed based on * their data type. Any unrecognized query parameter will always be parsed as a string. @@ -103,17 +102,17 @@ public GenericUrl() {} * compliant with, at least, RFC 3986. * * @param encodedUrl encoded URL, including any existing query parameters that should be parsed - * @throws IllegalArgumentException if URL has a syntax error + * @throws IllegalArgumentException if the URL has a syntax error */ public GenericUrl(String encodedUrl) { this(encodedUrl, false); } /** - * Constructs from an encoded URL. + * Constructs a GenericUrl from a string. * - *

Any known query parameters with pre-defined fields as data keys are parsed based on their - * data type. Any unrecognized query parameter are always parsed as a string. + *

Any known query parameters with pre-defined fields as data keys will be parsed based on + * their data type. Any unrecognized query parameter will always be parsed as a string. * *

Any {@link MalformedURLException} is wrapped in an {@link IllegalArgumentException}. * @@ -216,7 +215,6 @@ private GenericUrl( @Override public int hashCode() { - // TODO(yanivi): optimize? return build().hashCode(); } @@ -229,7 +227,6 @@ public boolean equals(Object obj) { return false; } GenericUrl other = (GenericUrl) obj; - // TODO(yanivi): optimize? return build().equals(other.build()); } diff --git a/google-http-client/src/main/java/com/google/api/client/http/UrlEncodedParser.java b/google-http-client/src/main/java/com/google/api/client/http/UrlEncodedParser.java index fb5ec5375..14c3238f7 100644 --- a/google-http-client/src/main/java/com/google/api/client/http/UrlEncodedParser.java +++ b/google-http-client/src/main/java/com/google/api/client/http/UrlEncodedParser.java @@ -83,7 +83,7 @@ public class UrlEncodedParser implements ObjectParser { public static void parse(String content, Object data) { parse(content, data, true); } - + /** * Parses the given URL-encoded content into the given data object of data key name/value pairs * using {@link #parse(Reader, Object)}. @@ -92,7 +92,7 @@ public static void parse(String content, Object data) { * @param data data key name/value pairs * @param decodeEnabled flag that specifies whether decoding should be enabled. */ - public static void parse(String content, Object data, boolean decodeEnabled) { + public static void parse(String content, Object data, boolean decodeEnabled) { if (content == null) { return; } @@ -103,6 +103,7 @@ public static void parse(String content, Object data, boolean decodeEnabled) { throw Throwables.propagate(exception); } } + /** * Parses the given URL-encoded content into the given data object of data key name/value pairs, * including support for repeating data key names. diff --git a/google-http-client/src/main/java/com/google/api/client/util/escape/CharEscapers.java b/google-http-client/src/main/java/com/google/api/client/util/escape/CharEscapers.java index 062e082d8..d75bea05c 100644 --- a/google-http-client/src/main/java/com/google/api/client/util/escape/CharEscapers.java +++ b/google-http-client/src/main/java/com/google/api/client/util/escape/CharEscapers.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2010 Google Inc. + * * Licensed 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 @@ -19,27 +20,26 @@ import java.nio.charset.StandardCharsets; /** - * Utility functions for dealing with {@code CharEscaper}s, and some commonly used {@code - * CharEscaper} instances. + * Utility functions for encoding and decoding URIs. * * @since 1.0 */ public final class CharEscapers { - private static final Escaper URI_ESCAPER = + private static final Escaper APPLICATION_X_WWW_FORM_URLENCODED = new PercentEscaper(PercentEscaper.SAFECHARS_URLENCODER, true); private static final Escaper URI_PATH_ESCAPER = - new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER, false); + new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER); private static final Escaper URI_RESERVED_ESCAPER = - new PercentEscaper(PercentEscaper.SAFE_PLUS_RESERVED_CHARS_URLENCODER, false); + new PercentEscaper(PercentEscaper.SAFE_PLUS_RESERVED_CHARS_URLENCODER); private static final Escaper URI_USERINFO_ESCAPER = - new PercentEscaper(PercentEscaper.SAFEUSERINFOCHARS_URLENCODER, false); + new PercentEscaper(PercentEscaper.SAFEUSERINFOCHARS_URLENCODER); private static final Escaper URI_QUERY_STRING_ESCAPER = - new PercentEscaper(PercentEscaper.SAFEQUERYSTRINGCHARS_URLENCODER, false); + new PercentEscaper(PercentEscaper.SAFEQUERYSTRINGCHARS_URLENCODER); /** * Escapes the string value so it can be safely included in URIs. For details on escaping URIs, @@ -69,18 +69,18 @@ public final class CharEscapers { * */ public static String escapeUri(String value) { - return URI_ESCAPER.escape(value); + return APPLICATION_X_WWW_FORM_URLENCODED.escape(value); } /** - * Percent-decodes a US-ASCII string into a Unicode string. UTF-8 encoding is used to determine + * Decodes application/x-www-form-urlencoded strings. The UTF-8 character set determines * what characters are represented by any consecutive sequences of the form "%XX". * - *

This replaces each occurrence of '+' with a space, ' '. So this method should not be used - * for non application/x-www-form-urlencoded strings such as host and path. + *

This replaces each occurrence of '+' with a space, ' '. This method should not be used + * for non-application/x-www-form-urlencoded strings such as host and path. * * @param uri a percent-encoded US-ASCII string - * @return a Unicode string + * @return a string without any percent escapes or plus signs */ public static String decodeUri(String uri) { try { @@ -92,11 +92,11 @@ public static String decodeUri(String uri) { } /** - * Decodes the path component of a URI. This must be done via a method that does not try to - * convert + into spaces(the behavior of {@link java.net.URLDecoder#decode(String, String)}). This + * Decodes the path component of a URI. This does not + * convert + into spaces (the behavior of {@link java.net.URLDecoder#decode(String, String)}). This * method transforms URI encoded values into their decoded symbols. * - *

i.e: {@code decodePath("%3Co%3E")} would return {@code ""} + *

e.g. {@code decodePath("%3Co%3E")} returns {@code ""} * * @param path the value to be decoded * @return decoded version of {@code path} diff --git a/google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java b/google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java index d55b5a0d4..33a48dce1 100644 --- a/google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java +++ b/google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.InputStream; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.junit.Test; diff --git a/google-http-client/src/test/java/com/google/api/client/util/escape/CharEscapersTest.java b/google-http-client/src/test/java/com/google/api/client/util/escape/CharEscapersTest.java index 0ad3d1e58..0a4e08809 100644 --- a/google-http-client/src/test/java/com/google/api/client/util/escape/CharEscapersTest.java +++ b/google-http-client/src/test/java/com/google/api/client/util/escape/CharEscapersTest.java @@ -38,12 +38,11 @@ public void testDecodeUri_IllegalArgumentException() { } private void subtestDecodeUri_IllegalArgumentException(String input) { - boolean thrown = false; try { CharEscapers.decodeUriPath(input); - } catch (IllegalArgumentException e) { - thrown = true; + fail(); + } catch (IllegalArgumentException expected) { + assertNotNull(expected.getMessage()); } - assertTrue(thrown); } }