You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ju...@apache.org on 2013/02/19 03:45:19 UTC
svn commit: r1447577 - in /commons/proper/codec/trunk/src: changes/
main/java/org/apache/commons/codec/binary/
Author: julius
Date: Tue Feb 19 02:45:18 2013
New Revision: 1447577
URL: http://svn.apache.org/r1447577
Log:
reverting r1447443 while we discuss it
Removed:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/ApacheModifiedMiGBase64.java
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/MiGBase64.original
Modified:
commons/proper/codec/trunk/src/changes/changes.xml
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java
Modified: commons/proper/codec/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/changes/changes.xml?rev=1447577&r1=1447576&r2=1447577&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/changes/changes.xml (original)
+++ commons/proper/codec/trunk/src/changes/changes.xml Tue Feb 19 02:45:18 2013
@@ -48,7 +48,6 @@ The <action> type attribute can be add,u
</release>
-->
<release version="1.8" date="TBA" description="Feature and fix release.">
- <action dev="julius" type="fix" issue="CODEC-166">Base64 could be faster.</action>
<action dev="julius" type="update" issue="CODEC-167">Adds JUnit to test our decode with pad character in the middle.</action>
<action dev="ggregory" type="add" issue="CODEC-161" due-to="crice">Add Match Rating Approach (MRA) phonetic algorithm encoder.</action>
<action dev="ggregory" type="fix" issue="CODEC-163" due-to="leo141">ColognePhonetic encoder unneccessarily creates many char arrays on every loop run.</action>
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java?rev=1447577&r1=1447576&r2=1447577&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java Tue Feb 19 02:45:18 2013
@@ -480,25 +480,6 @@ public class Base64 extends BaseNCodec {
}
}
- @Override
- public byte[] decode(final byte[] pArray) {
- if (pArray == null || pArray.length == 0) {
- return pArray;
- }
- return ApacheModifiedMiGBase64.decode(pArray);
- }
-
- @Override
- public byte[] encode(final byte[] pArray) {
- if (pArray == null || pArray.length == 0) {
- return pArray;
- }
- return ApacheModifiedMiGBase64.encodeToByte(
- pArray, lineSeparator != null, isUrlSafe(), Integer.MAX_VALUE, lineSeparator, lineLength
- );
- }
-
-
/**
* Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the
* method treats whitespace as valid.
@@ -582,9 +563,7 @@ public class Base64 extends BaseNCodec {
* @since 1.4 (NOTE: 1.4 chunked the output, whereas 1.5 does not).
*/
public static String encodeBase64String(final byte[] binaryData) {
- return ApacheModifiedMiGBase64.encodeToString(
- binaryData, false, false, Integer.MAX_VALUE
- );
+ return StringUtils.newStringUtf8(encodeBase64(binaryData, false));
}
/**
@@ -610,9 +589,7 @@ public class Base64 extends BaseNCodec {
* @since 1.4
*/
public static String encodeBase64URLSafeString(final byte[] binaryData) {
- return ApacheModifiedMiGBase64.encodeToString(
- binaryData, false, true, Integer.MAX_VALUE
- );
+ return StringUtils.newStringUtf8(encodeBase64(binaryData, false, true));
}
/**
@@ -679,11 +656,23 @@ public class Base64 extends BaseNCodec {
*/
public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked,
final boolean urlSafe, final int maxResultSize) {
- return ApacheModifiedMiGBase64.encodeToByte(
- binaryData, isChunked, urlSafe, maxResultSize
- );
- }
+ if (binaryData == null || binaryData.length == 0) {
+ return binaryData;
+ }
+
+ // Create this so can use the super-class method
+ // Also ensures that the same roundings are performed by the ctor and the code
+ final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
+ final long len = b64.getEncodedLength(binaryData);
+ if (len > maxResultSize) {
+ throw new IllegalArgumentException("Input array too big, the output array would be bigger (" +
+ len +
+ ") than the specified maximum size of " +
+ maxResultSize);
+ }
+ return b64.encode(binaryData);
+ }
/**
* Decodes a Base64 String into octets
@@ -694,10 +683,7 @@ public class Base64 extends BaseNCodec {
* @since 1.4
*/
public static byte[] decodeBase64(final String base64String) {
- if (base64String == null) { return null; }
- if ("".equals(base64String)) { return new byte[0]; }
-
- return ApacheModifiedMiGBase64.decode(base64String.toCharArray());
+ return new Base64().decode(base64String);
}
/**
@@ -708,9 +694,7 @@ public class Base64 extends BaseNCodec {
* @return Array containing decoded data.
*/
public static byte[] decodeBase64(final byte[] base64Data) {
- if (base64Data == null || base64Data.length == 0) { return base64Data; }
-
- return ApacheModifiedMiGBase64.decode(base64Data);
+ return new Base64().decode(base64Data);
}
// Implementation of the Encoder Interface