You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/01/26 10:17:06 UTC
svn commit: r1063649 -
/commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java
Author: sebb
Date: Wed Jan 26 09:17:06 2011
New Revision: 1063649
URL: http://svn.apache.org/viewvc?rev=1063649&view=rev
Log:
Document (and simplify) code dealing with trailing partial decode input
Modified:
commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java
Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java?rev=1063649&r1=1063648&r2=1063649&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java Wed Jan 26 09:17:06 2011
@@ -563,15 +563,19 @@ public class Base64 implements BinaryEnc
resizeBuffer();
}
- x = x << 6;
+ // We have some spare bits remaining
+ // Output all whole multiples of 8 bits and ignore the rest
switch (modulus) {
- case 2 :
- x = x << 6;
- buffer[pos++] = (byte) ((x >> 16) & MASK_8BITS);
+ // case 1: // 6 bits - ignore entirely
+ // break;
+ case 2 : // 12 bits = 8 + 4
+ x = x >> 4;
+ buffer[pos++] = (byte) ((x) & MASK_8BITS);
break;
- case 3 :
- buffer[pos++] = (byte) ((x >> 16) & MASK_8BITS);
+ case 3 : // 18 bits = 8 + 8 + 2
+ x = x >> 2;
buffer[pos++] = (byte) ((x >> 8) & MASK_8BITS);
+ buffer[pos++] = (byte) ((x) & MASK_8BITS);
break;
}
}