public byte[] decode(String s){
  byte[] b=new byte[(s.length() / 4) * 3];
  int cycle=0;
  int combined=0;
  int j=0;
  int len=s.length();
  int dummies=0;
  for (int i=0; i < len; i++) {
    int c=s.charAt(i);
    int value=(c <= 255) ? charToValue[c] : IGNORE;
switch (value) {
case IGNORE:
      break;
case PAD:
    value=0;
  dummies++;
default :
switch (cycle) {
case 0:
  combined=value;
cycle=1;
break;
case 1:
combined<<=6;
combined|=value;
cycle=2;
break;
case 2:
combined<<=6;
combined|=value;
cycle=3;
break;
case 3:
combined<<=6;
combined|=value;
b[j + 2]=(byte)combined;
combined>>>=8;
b[j + 1]=(byte)combined;
combined>>>=8;
b[j]=(byte)combined;
j+=3;
cycle=0;
break;
}
break;
}
}
if (cycle != 0) {
throw new ArrayIndexOutOfBoundsException("Input to decode not an even multiple of 4 characters; pad with =.");
}
j-=dummies;
if (b.length != j) {
byte[] b2=new byte[j];
System.arraycopy(b,0,b2,0,j);
b=b2;
}
return b;
}

public byte [ ] decode ( String s ) { byte [ ] b = new byte [ ( s . length ( ) / 4 ) * 3 ] ; int cycle = 0 ; int combined = 0 ; int j = 0 ; int len = s . length ( ) ; int dummies = 0 ; for ( int i = 0 ; i < len ; i ++ ) { int c = s . charAt ( i ) ; int value = ( c <= 255 ) ? charToValue [ c ] : IGNORE ; switch ( value ) { case IGNORE : break ; case PAD : value = 0 ; dummies ++ ; default : switch ( cycle ) { case 0 : combined = value ; cycle = 1 ; break ; case 1 : combined <<= 6 ; combined |= value ; cycle = 2 ; break ; case 2 : combined <<= 6 ; combined |= value ; cycle = 3 ; break ; case 3 : combined <<= 6 ; combined |= value ; b [ j + 2 ] = ( byte ) combined ; combined >>>= 8 ; b [ j + 1 ] = ( byte ) combined ; combined >>>= 8 ; b [ j ] = ( byte ) combined ; j += 3 ; cycle = 0 ; break ; } break ; } } if ( cycle != 0 ) { throw new ArrayIndexOutOfBoundsException ( "Input to decode not an even multiple of 4 characters; pad with =." ) ; } j -= dummies ; if ( b . length != j ) { byte [ ] b2 = new byte [ j ] ; System . arraycopy ( b , 0 , b2 , 0 , j ) ; b = b2 ; } return b ; }
decode a well - formed complete base64 string back into an array of bytes . it must have an even multiple of 4 data characters ( not counting \ n ) , padded out with = as needed .
