Skip to content

Commit b81a9b2

Browse files
committed
Rollback base64 changes
This reverts ef9f914 and implicitly c6d5c60
1 parent c6d5c60 commit b81a9b2

File tree

2 files changed

+27
-102
lines changed

2 files changed

+27
-102
lines changed

google-http-client/src/main/java/com/google/api/client/util/Base64.java

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414

1515
package com.google.api.client.util;
1616

17-
import com.google.common.io.BaseEncoding;
18-
1917
/**
20-
* Proxy for base 64 encoding/decoding which matches the Base64 interface in Apache Commons (for
21-
* historical reasons).
18+
* Proxy for version 1.6 (or newer) of the Apache Commons Codec
19+
* {@link org.apache.commons.codec.binary.Base64} implementation.
20+
*
21+
* <p>
22+
* This is needed in order to support platforms like Android which already include an older version
23+
* of the Apache Commons Codec (Android includes version 1.3). To avoid a dependency library
24+
* conflict, this library includes a reduced private copy of version 1.6 (or newer) of the Apache
25+
* Commons Codec (using a tool like jarjar).
26+
* </p>
2227
*
23-
* @author Yaniv Inbar
2428
* @since 1.8
29+
* @author Yaniv Inbar
2530
*/
2631
public class Base64 {
2732

@@ -30,41 +35,36 @@ public class Base64 {
3035
*
3136
* @param binaryData binary data to encode or {@code null} for {@code null} result
3237
* @return byte[] containing Base64 characters in their UTF-8 representation or {@code null} for
33-
* {@code null} input
38+
* {@code null} input
39+
* @see org.apache.commons.codec.binary.Base64#encodeBase64(byte[])
3440
*/
3541
public static byte[] encodeBase64(byte[] binaryData) {
36-
if (binaryData == null) {
37-
return null;
38-
}
39-
return BaseEncoding.base64().encode(binaryData).getBytes();
42+
return org.apache.commons.codec.binary.Base64.encodeBase64(binaryData);
4043
}
4144

4245
/**
4346
* Encodes binary data using the base64 algorithm but does not chunk the output.
4447
*
4548
* @param binaryData binary data to encode or {@code null} for {@code null} result
4649
* @return String containing Base64 characters or {@code null} for {@code null} input
50+
* @see org.apache.commons.codec.binary.Base64#encodeBase64String(byte[])
4751
*/
4852
public static String encodeBase64String(byte[] binaryData) {
49-
if (binaryData == null) {
50-
return null;
51-
}
52-
return BaseEncoding.base64().encode(binaryData);
53+
return org.apache.commons.codec.binary.Base64.encodeBase64String(binaryData);
5354
}
5455

56+
5557
/**
5658
* Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the
5759
* output. The url-safe variation emits - and _ instead of + and / characters.
5860
*
5961
* @param binaryData binary data to encode or {@code null} for {@code null} result
6062
* @return byte[] containing Base64 characters in their UTF-8 representation or {@code null} for
61-
* {@code null} input
63+
* {@code null} input
64+
* @see org.apache.commons.codec.binary.Base64#encodeBase64URLSafe(byte[])
6265
*/
6366
public static byte[] encodeBase64URLSafe(byte[] binaryData) {
64-
if (binaryData == null) {
65-
return null;
66-
}
67-
return BaseEncoding.base64Url().omitPadding().encode(binaryData).getBytes();
67+
return org.apache.commons.codec.binary.Base64.encodeBase64URLSafe(binaryData);
6868
}
6969

7070
/**
@@ -73,45 +73,34 @@ public static byte[] encodeBase64URLSafe(byte[] binaryData) {
7373
*
7474
* @param binaryData binary data to encode or {@code null} for {@code null} result
7575
* @return String containing Base64 characters or {@code null} for {@code null} input
76+
* @see org.apache.commons.codec.binary.Base64#encodeBase64URLSafeString(byte[])
7677
*/
7778
public static String encodeBase64URLSafeString(byte[] binaryData) {
78-
if (binaryData == null) {
79-
return null;
80-
}
81-
return BaseEncoding.base64Url().omitPadding().encode(binaryData);
79+
return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(binaryData);
8280
}
8381

8482
/**
8583
* Decodes Base64 data into octets.
8684
*
8785
* @param base64Data Byte array containing Base64 data or {@code null} for {@code null} result
8886
* @return Array containing decoded data or {@code null} for {@code null} input
87+
* @see org.apache.commons.codec.binary.Base64#decodeBase64(byte[])
8988
*/
9089
public static byte[] decodeBase64(byte[] base64Data) {
91-
if (base64Data == null) {
92-
return null;
93-
}
94-
return decodeBase64(new String(base64Data));
90+
return org.apache.commons.codec.binary.Base64.decodeBase64(base64Data);
9591
}
9692

9793
/**
9894
* Decodes a Base64 String into octets.
9995
*
10096
* @param base64String String containing Base64 data or {@code null} for {@code null} result
10197
* @return Array containing decoded data or {@code null} for {@code null} input
98+
* @see org.apache.commons.codec.binary.Base64#decodeBase64(String)
10299
*/
103100
public static byte[] decodeBase64(String base64String) {
104-
if (base64String == null) {
105-
return null;
106-
}
107-
108-
base64String = base64String.replace("\r", "");
109-
base64String = base64String.replace("\n", "");
101+
return org.apache.commons.codec.binary.Base64.decodeBase64(base64String);
102+
}
110103

111-
try {
112-
return BaseEncoding.base64().decode(base64String);
113-
} catch (IllegalArgumentException e) {
114-
return BaseEncoding.base64Url().omitPadding().decode(base64String);
115-
}
104+
private Base64() {
116105
}
117106
}

google-http-client/src/test/java/com/google/api/client/util/Base64Test.java

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)