Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions google-http-client-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<configuration>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
<excludeArtifactIds>android,opengl-api,xmlParserAPIs,commons-codec,json</excludeArtifactIds>
<excludeArtifactIds>android,opengl-api,xmlParserAPIs,json</excludeArtifactIds>
</configuration>
</execution>
<execution>
Expand All @@ -92,7 +92,7 @@
<classifier>sources</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/libs-sources</outputDirectory>
<excludeArtifactIds>android,opengl-api,xmlParserAPIs,commons-codec,json</excludeArtifactIds>
<excludeArtifactIds>android,opengl-api,xmlParserAPIs,json</excludeArtifactIds>
</configuration>
</execution>
</executions>
Expand Down
67 changes: 0 additions & 67 deletions google-http-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<links>
<link>http://download.oracle.com/javase/7/docs/api/</link>
<link>https://google.github.io/guava/releases/${project.guava.version}/api/docs/</link>
<link>https://commons.apache.org/proper/commons-codec/archives/${project.commons-codec.version}/apidocs/</link>
</links>
<doctitle>${project.name} ${project.version}</doctitle>
<windowtitle>${project.artifactId} ${project.version}</windowtitle>
Expand All @@ -41,68 +40,6 @@
</execution>
</executions>
</plugin>
<!-- Use jarjar to include a private copy of Apache Commons Codec library
to avoid a runtime dependency conflict with Android which includes
an older version of that library, as well as Guava JDK5. -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>jarjar-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jarjar</goal>
</goals>
<configuration>
<includes>
<include>commons-codec:commons-codec</include>
<include>com.google.guava:guava</include>
</includes>
<rules>
<rule>
<pattern>org.apache.commons.codec.**</pattern>
<result>com.google.api.client.repackaged.org.apache.commons.codec.@1</result>
</rule>
<rule>
<pattern>com.google.common.**</pattern>
<result>com.google.api.client.repackaged.com.google.common.@1</result>
</rule>
<keep>
<pattern>com.google.api.client.**</pattern>
</keep>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<!-- Remove extraneous files from the jarjar'ed Apache Commons Codec
Library. -->
<execution>
<id>scrub</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<jar destfile="target/scrubbed.jar" filesetmanifest="merge">
<zipfileset src="target/google-http-client-${project.version}.jar">
<exclude name="**/org/apache/commons/codec/language/bm/*.txt"/>
<exclude name="META-INF/*.txt"/>
<exclude name="META-INF/maven/**"/>
</zipfileset>
</jar>
<move file="target/scrubbed.jar" tofile="target/google-http-client-${project.version}.jar"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
Expand Down Expand Up @@ -165,10 +102,6 @@
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>com.google.j2objc</groupId>
<artifactId>j2objc-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>
* 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).
* </p>
* Proxy for handling Base64 encoding/decoding.
*
* @since 1.8
* @author Yaniv Inbar
Expand All @@ -36,21 +31,19 @@ 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));
}

/**
* Encodes binary data using the base64 algorithm but does not chunk the output.
*
* @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);
}


Expand All @@ -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));
}

/**
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@
package com.google.api.client.util;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;


/**
* Utilities for strings.
*
* <p>
* 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).
* </p>
*
* @since 1.8
* @author Yaniv Inbar
*/
Expand All @@ -48,13 +41,15 @@ public class StringUtils {
* @return encoded bytes, or <code>null</code> if the input string was <code>null</code>
* @throws IllegalStateException Thrown when the charset is missing, which should be never
* according the the Java specification.
* @see <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/nio/charset/Charset.html"
* @see <a href="http://download.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html"
* >Standard charsets</a>
* @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);
}

/**
Expand All @@ -66,11 +61,13 @@ public static byte[] getBytesUtf8(String string) {
* charset, or <code>null</code> if the input byte array was <code>null</code>.
* @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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@
<artifactId>httpclient</artifactId>
<version>${project.httpclient.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${project.commons-codec.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -436,7 +431,6 @@
<link>http://fasterxml.github.com/jackson-core/javadoc/${project.jackson-core2.version}/</link>
<link>https://www.javadoc.io/doc/com.google.code.gson/gson/${project.gson.version}</link>
<link>https://google.github.io/guava/releases/${project.guava.version}/api/docs/</link>
<link>https://commons.apache.org/proper/commons-codec/archives/${project.commons-codec.version}/apidocs/</link>
</links>
<doctitle>Google HTTP Client Library for Java ${project.version}</doctitle>
<excludePackageNames>com.google.api.client.findbugs:com.google.api.client.test.:com.google.api.services</excludePackageNames>
Expand Down Expand Up @@ -575,7 +569,6 @@
<project.guava.version>26.0-android</project.guava.version>
<project.xpp3.version>1.1.4c</project.xpp3.version>
<project.commons-logging.version>1.1.1</project.commons-logging.version>
<project.commons-codec.version>1.11</project.commons-codec.version>
<project.httpclient.version>4.5.5</project.httpclient.version>
<project.jdo2-api.version>2.3-eb</project.jdo2-api.version>
<project.datanucleus-core.version>3.2.2</project.datanucleus-core.version>
Expand Down