public int decode(byte[] data,int off,int length,OutputStream out) throws IOException {
  byte[] bytes;
  byte b1;
  byte b2;
  byte b3;
  byte b4;
  int outLen=0;
  int end=off + length;
  while (end > 0) {
    if (!ignore((char)data[end - 1]))     break;
    end--;
  }
  int i=off;
  int finish=end - 4;
  while (i < finish) {
    while ((i < finish) && ignore((char)data[i]))     i++;
    b1=decodingTable[data[i++]];
    while ((i < finish) && ignore((char)data[i]))     i++;
    b2=decodingTable[data[i++]];
    while ((i < finish) && ignore((char)data[i]))     i++;
    b3=decodingTable[data[i++]];
    while ((i < finish) && ignore((char)data[i]))     i++;
    b4=decodingTable[data[i++]];
    out.write((b1 << 2) | (b2 >> 4));
    out.write((b2 << 4) | (b3 >> 2));
    out.write((b3 << 6) | b4);
    outLen+=3;
  }
  if (data[end - 2] == padding) {
    b1=decodingTable[data[end - 4]];
    b2=decodingTable[data[end - 3]];
    out.write((b1 << 2) | (b2 >> 4));
    outLen+=1;
  }
 else   if (data[end - 1] == padding) {
    b1=decodingTable[data[end - 4]];
    b2=decodingTable[data[end - 3]];
    b3=decodingTable[data[end - 2]];
    out.write((b1 << 2) | (b2 >> 4));
    out.write((b2 << 4) | (b3 >> 2));
    outLen+=2;
  }
 else {
    b1=decodingTable[data[end - 4]];
    b2=decodingTable[data[end - 3]];
    b3=decodingTable[data[end - 2]];
    b4=decodingTable[data[end - 1]];
    out.write((b1 << 2) | (b2 >> 4));
    out.write((b2 << 4) | (b3 >> 2));
    out.write((b3 << 6) | b4);
    outLen+=3;
  }
  return outLen;
}

public int decode ( byte [ ] data , int off , int length , OutputStream out ) throws IOException { byte [ ] bytes ; byte b1 ; byte b2 ; byte b3 ; byte b4 ; int outLen = 0 ; int end = off + length ; while ( end > 0 ) { if ( ! ignore ( ( char ) data [ end - 1 ] ) ) break ; end -- ; } int i = off ; int finish = end - 4 ; while ( i < finish ) { while ( ( i < finish ) && ignore ( ( char ) data [ i ] ) ) i ++ ; b1 = decodingTable [ data [ i ++ ] ] ; while ( ( i < finish ) && ignore ( ( char ) data [ i ] ) ) i ++ ; b2 = decodingTable [ data [ i ++ ] ] ; while ( ( i < finish ) && ignore ( ( char ) data [ i ] ) ) i ++ ; b3 = decodingTable [ data [ i ++ ] ] ; while ( ( i < finish ) && ignore ( ( char ) data [ i ] ) ) i ++ ; b4 = decodingTable [ data [ i ++ ] ] ; out . write ( ( b1 << 2 ) | ( b2 > > 4 ) ) ; out . write ( ( b2 << 4 ) | ( b3 > > 2 ) ) ; out . write ( ( b3 << 6 ) | b4 ) ; outLen += 3 ; } if ( data [ end - 2 ] == padding ) { b1 = decodingTable [ data [ end - 4 ] ] ; b2 = decodingTable [ data [ end - 3 ] ] ; out . write ( ( b1 << 2 ) | ( b2 > > 4 ) ) ; outLen += 1 ; } else if ( data [ end - 1 ] == padding ) { b1 = decodingTable [ data [ end - 4 ] ] ; b2 = decodingTable [ data [ end - 3 ] ] ; b3 = decodingTable [ data [ end - 2 ] ] ; out . write ( ( b1 << 2 ) | ( b2 > > 4 ) ) ; out . write ( ( b2 << 4 ) | ( b3 > > 2 ) ) ; outLen += 2 ; } else { b1 = decodingTable [ data [ end - 4 ] ] ; b2 = decodingTable [ data [ end - 3 ] ] ; b3 = decodingTable [ data [ end - 2 ] ] ; b4 = decodingTable [ data [ end - 1 ] ] ; out . write ( ( b1 << 2 ) | ( b2 > > 4 ) ) ; out . write ( ( b2 << 4 ) | ( b3 > > 2 ) ) ; out . write ( ( b3 << 6 ) | b4 ) ; outLen += 3 ; } return outLen ; }
decode the base 64 encoded byte data writing it to the given output stream , whitespace characters will be ignored .
