codes[ data[ix] ] < 0 ) --tempLen;// ignore non-valid chars and padding } // calculate required length: //-- 3 bytes for every 4 valid base64 chars //-- plus 2 bytes if there are 3 extra base64 chars, // or plus 1 byte if there are 2 extra.
int len = (tempLen / 4) * 3; if ((tempLen % 4) == 3) len += 2; if ((tempLen % 4) == 2) len += 1;
byte[] out = new byte[len];
int shift = 0; // # of excess bits stored in accum int accum = 0; // excess bits int index = 0;
// we now go through the entire array (NOT using the 'tempLen' value) for (int ix=0; ix<data.length; ix++) { int value = (data[ix]>255)? -1: codes[ data[ix] ];
if ( value >= 0 ) // skip over non-code { accum <<= 6;// bits shift up by 6 each time thru shift += 6; // loop, with new bits being put in accum