Skip to content

Commit 3e725d7

Browse files
committed
Document (and simplify) code dealing with trailing partial decode input
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1063649 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6e883fa commit 3e725d7

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,19 @@ void decode(byte[] in, int inPos, int inAvail) {
563563
resizeBuffer();
564564
}
565565

566-
x = x << 6;
566+
// We have some spare bits remaining
567+
// Output all whole multiples of 8 bits and ignore the rest
567568
switch (modulus) {
568-
case 2 :
569-
x = x << 6;
570-
buffer[pos++] = (byte) ((x >> 16) & MASK_8BITS);
569+
// case 1: // 6 bits - ignore entirely
570+
// break;
571+
case 2 : // 12 bits = 8 + 4
572+
x = x >> 4;
573+
buffer[pos++] = (byte) ((x) & MASK_8BITS);
571574
break;
572-
case 3 :
573-
buffer[pos++] = (byte) ((x >> 16) & MASK_8BITS);
575+
case 3 : // 18 bits = 8 + 8 + 2
576+
x = x >> 2;
574577
buffer[pos++] = (byte) ((x >> 8) & MASK_8BITS);
578+
buffer[pos++] = (byte) ((x) & MASK_8BITS);
575579
break;
576580
}
577581
}

0 commit comments

Comments
 (0)