diff --git a/google-http-client-assembly/pom.xml b/google-http-client-assembly/pom.xml index 691062532..91af0998a 100644 --- a/google-http-client-assembly/pom.xml +++ b/google-http-client-assembly/pom.xml @@ -79,7 +79,7 @@ false ${project.build.directory}/libs - android,opengl-api,xmlParserAPIs,commons-codec,json + android,opengl-api,xmlParserAPIs,json @@ -92,7 +92,7 @@ sources false ${project.build.directory}/libs-sources - android,opengl-api,xmlParserAPIs,commons-codec,json + android,opengl-api,xmlParserAPIs,json diff --git a/google-http-client/pom.xml b/google-http-client/pom.xml index 8243c83d0..a160df1d0 100644 --- a/google-http-client/pom.xml +++ b/google-http-client/pom.xml @@ -23,7 +23,6 @@ http://download.oracle.com/javase/7/docs/api/ https://google.github.io/guava/releases/${project.guava.version}/api/docs/ - https://commons.apache.org/proper/commons-codec/archives/${project.commons-codec.version}/apidocs/ ${project.name} ${project.version} ${project.artifactId} ${project.version} @@ -41,68 +40,6 @@ - - - org.sonatype.plugins - jarjar-maven-plugin - 1.9 - - - package - - jarjar - - - - commons-codec:commons-codec - com.google.guava:guava - - - - org.apache.commons.codec.** - com.google.api.client.repackaged.org.apache.commons.codec.@1 - - - com.google.common.** - com.google.api.client.repackaged.com.google.common.@1 - - - com.google.api.client.** - - - - - - - - maven-antrun-plugin - 1.8 - - - - scrub - package - - run - - - - - - - - - - - - - - - - maven-jar-plugin @@ -165,10 +102,6 @@ mockito-all test - - commons-codec - commons-codec - com.google.j2objc j2objc-annotations diff --git a/google-http-client/src/main/java/com/google/api/client/util/Base64.java b/google-http-client/src/main/java/com/google/api/client/util/Base64.java index f93b0c095..ac3650f0a 100644 --- a/google-http-client/src/main/java/com/google/api/client/util/Base64.java +++ b/google-http-client/src/main/java/com/google/api/client/util/Base64.java @@ -14,16 +14,11 @@ package com.google.api.client.util; +import com.google.common.io.BaseEncoding; +import com.google.common.io.BaseEncoding.DecodingException; + /** - * Proxy for version 1.6 (or newer) of the Apache Commons Codec - * {@link org.apache.commons.codec.binary.Base64} implementation. - * - *

- * This is needed in order to support platforms like Android which already include an older version - * of the Apache Commons Codec (Android includes version 1.3). To avoid a dependency library - * conflict, this library includes a reduced private copy of version 1.6 (or newer) of the Apache - * Commons Codec (using a tool like jarjar). - *

+ * Proxy for handling Base64 encoding/decoding. * * @since 1.8 * @author Yaniv Inbar @@ -36,10 +31,9 @@ public class Base64 { * @param binaryData binary data to encode or {@code null} for {@code null} result * @return byte[] containing Base64 characters in their UTF-8 representation or {@code null} for * {@code null} input - * @see org.apache.commons.codec.binary.Base64#encodeBase64(byte[]) */ public static byte[] encodeBase64(byte[] binaryData) { - return org.apache.commons.codec.binary.Base64.encodeBase64(binaryData); + return StringUtils.getBytesUtf8(encodeBase64String(binaryData)); } /** @@ -47,10 +41,9 @@ public static byte[] encodeBase64(byte[] binaryData) { * * @param binaryData binary data to encode or {@code null} for {@code null} result * @return String containing Base64 characters or {@code null} for {@code null} input - * @see org.apache.commons.codec.binary.Base64#encodeBase64String(byte[]) */ public static String encodeBase64String(byte[] binaryData) { - return org.apache.commons.codec.binary.Base64.encodeBase64String(binaryData); + return BaseEncoding.base64().encode(binaryData); } @@ -61,10 +54,9 @@ public static String encodeBase64String(byte[] binaryData) { * @param binaryData binary data to encode or {@code null} for {@code null} result * @return byte[] containing Base64 characters in their UTF-8 representation or {@code null} for * {@code null} input - * @see org.apache.commons.codec.binary.Base64#encodeBase64URLSafe(byte[]) */ public static byte[] encodeBase64URLSafe(byte[] binaryData) { - return org.apache.commons.codec.binary.Base64.encodeBase64URLSafe(binaryData); + return StringUtils.getBytesUtf8(encodeBase64URLSafeString(binaryData)); } /** @@ -73,32 +65,38 @@ public static byte[] encodeBase64URLSafe(byte[] binaryData) { * * @param binaryData binary data to encode or {@code null} for {@code null} result * @return String containing Base64 characters or {@code null} for {@code null} input - * @see org.apache.commons.codec.binary.Base64#encodeBase64URLSafeString(byte[]) */ public static String encodeBase64URLSafeString(byte[] binaryData) { - return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(binaryData); + return BaseEncoding.base64Url().omitPadding().encode(binaryData); } /** - * Decodes Base64 data into octets. + * Decodes Base64 data into octets. Note that this method handles both URL-safe and + * non-URL-safe base 64 encoded inputs. * * @param base64Data Byte array containing Base64 data or {@code null} for {@code null} result * @return Array containing decoded data or {@code null} for {@code null} input - * @see org.apache.commons.codec.binary.Base64#decodeBase64(byte[]) */ public static byte[] decodeBase64(byte[] base64Data) { - return org.apache.commons.codec.binary.Base64.decodeBase64(base64Data); + return decodeBase64(StringUtils.newStringUtf8(base64Data)); } /** - * Decodes a Base64 String into octets. + * Decodes a Base64 String into octets. Note that this method handles both URL-safe and + * non-URL-safe base 64 encoded strings. * * @param base64String String containing Base64 data or {@code null} for {@code null} result * @return Array containing decoded data or {@code null} for {@code null} input - * @see org.apache.commons.codec.binary.Base64#decodeBase64(String) */ public static byte[] decodeBase64(String base64String) { - return org.apache.commons.codec.binary.Base64.decodeBase64(base64String); + try { + return BaseEncoding.base64().decode(base64String); + } catch (IllegalArgumentException e) { + if (e.getCause() instanceof DecodingException) { + return BaseEncoding.base64Url().decode(base64String); + } + throw e; + } } private Base64() { diff --git a/google-http-client/src/main/java/com/google/api/client/util/StringUtils.java b/google-http-client/src/main/java/com/google/api/client/util/StringUtils.java index 8d0c92532..80b1273cc 100644 --- a/google-http-client/src/main/java/com/google/api/client/util/StringUtils.java +++ b/google-http-client/src/main/java/com/google/api/client/util/StringUtils.java @@ -15,19 +15,12 @@ package com.google.api.client.util; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; /** * Utilities for strings. * - *

- * Some of these methods are a proxy for version 1.6 (or newer) of the Apache Commons Codec - * {@link StringUtils} implementation. This is needed in order to support platforms like Android - * which already include an older version of the Apache Commons Codec (Android includes version - * 1.3). To avoid a dependency library conflict, this library includes a reduced private copy of - * version 1.6 (or newer) of the Apache Commons Codec (using a tool like jarjar). - *

- * * @since 1.8 * @author Yaniv Inbar */ @@ -48,13 +41,15 @@ public class StringUtils { * @return encoded bytes, or null if the input string was null * @throws IllegalStateException Thrown when the charset is missing, which should be never * according the the Java specification. - * @see Standard charsets - * @see org.apache.commons.codec.binary.StringUtils#getBytesUtf8(String) * @since 1.8 */ public static byte[] getBytesUtf8(String string) { - return org.apache.commons.codec.binary.StringUtils.getBytesUtf8(string); + if (string == null) { + return null; + } + return string.getBytes(StandardCharsets.UTF_8); } /** @@ -66,11 +61,13 @@ public static byte[] getBytesUtf8(String string) { * charset, or null if the input byte array was null. * @throws IllegalStateException Thrown when a {@link UnsupportedEncodingException} is caught, * which should never happen since the charset is required. - * @see org.apache.commons.codec.binary.StringUtils#newStringUtf8(byte[]) * @since 1.8 */ public static String newStringUtf8(byte[] bytes) { - return org.apache.commons.codec.binary.StringUtils.newStringUtf8(bytes); + if (bytes == null) { + return null; + } + return new String(bytes, StandardCharsets.UTF_8); } private StringUtils() { diff --git a/google-http-client/src/test/java/com/google/api/client/util/StringUtilsTest.java b/google-http-client/src/test/java/com/google/api/client/util/StringUtilsTest.java index 0f7887197..3606f3ba3 100644 --- a/google-http-client/src/test/java/com/google/api/client/util/StringUtilsTest.java +++ b/google-http-client/src/test/java/com/google/api/client/util/StringUtilsTest.java @@ -40,7 +40,15 @@ public void testToBytesUtf8() { Assert.assertArrayEquals(SAMPLE_UTF8, StringUtils.getBytesUtf8(SAMPLE)); } + public void testToBytesUtf8Null() { + assertNull(StringUtils.getBytesUtf8(null)); + } + public void testFromBytesUtf8() { assertEquals(SAMPLE, StringUtils.newStringUtf8(SAMPLE_UTF8)); } + + public void testFromBytesUtf8Null() { + assertNull(StringUtils.newStringUtf8(null)); + } } diff --git a/pom.xml b/pom.xml index 84c905f42..546342f52 100644 --- a/pom.xml +++ b/pom.xml @@ -150,11 +150,6 @@ httpclient ${project.httpclient.version}
- - commons-codec - commons-codec - ${project.commons-codec.version} - com.google.guava guava @@ -436,7 +431,6 @@ http://fasterxml.github.com/jackson-core/javadoc/${project.jackson-core2.version}/ https://www.javadoc.io/doc/com.google.code.gson/gson/${project.gson.version} https://google.github.io/guava/releases/${project.guava.version}/api/docs/ - https://commons.apache.org/proper/commons-codec/archives/${project.commons-codec.version}/apidocs/ Google HTTP Client Library for Java ${project.version} com.google.api.client.findbugs:com.google.api.client.test.:com.google.api.services @@ -575,7 +569,6 @@ 26.0-android 1.1.4c 1.1.1 - 1.11 4.5.5 2.3-eb 3.2.2