public static byte[] decode(byte[] in,int len){
  final int inLength=Math.min(in.length,len);
  ByteArrayOutputStream output=new ByteArrayOutputStream((inLength / 4) * 3 + 3);
  int[] pos=new int[1];
  try {
    while (pos[0] < inLength) {
      int byteTripletAsInt=0;
      for (int j=0; j < 4; j++) {
        byte c=getNextByte(in,pos,inLength);
        if (c == END_OF_INPUT || c == PAD_AS_BYTE) {
switch (j) {
case 0:
case 1:
            return (c == END_OF_INPUT) ? output.toByteArray() : null;
case 2:
          if (c == END_OF_INPUT) {
            return checkNoTrailingAndReturn(output,in,pos[0],inLength);
          }
        pos[0]++;
      c=getNextByte(in,pos,inLength);
    if (c == END_OF_INPUT) {
      return checkNoTrailingAndReturn(output,in,pos[0],inLength);
    }
  if (c == PAD_AS_BYTE) {
    byteTripletAsInt>>=4;
    output.write(byteTripletAsInt);
    return checkNoTrailingAndReturn(output,in,pos[0],inLength);
  }
return null;
case 3:
if (c == PAD_AS_BYTE) {
byteTripletAsInt>>=2;
output.write(byteTripletAsInt >> 8);
output.write(byteTripletAsInt & 0xff);
}
return checkNoTrailingAndReturn(output,in,pos[0],inLength);
}
}
 else {
byteTripletAsInt<<=6;
byteTripletAsInt+=(c & 0xff);
pos[0]++;
}
}
output.write(byteTripletAsInt >> 16);
output.write((byteTripletAsInt >> 8) & 0xff);
output.write(byteTripletAsInt & 0xff);
}
return checkNoTrailingAndReturn(output,in,pos[0],inLength);
}
 catch (InvalidBase64ByteException e) {
return null;
}
}

public static byte [ ] decode ( byte [ ] in , int len ) { final int inLength = Math . min ( in . length , len ) ; ByteArrayOutputStream output = new ByteArrayOutputStream ( ( inLength / 4 ) * 3 + 3 ) ; int [ ] pos = new int [ 1 ] ; try { while ( pos [ 0 ] < inLength ) { int byteTripletAsInt = 0 ; for ( int j = 0 ; j < 4 ; j ++ ) { byte c = getNextByte ( in , pos , inLength ) ; if ( c == END_OF_INPUT || c == PAD_AS_BYTE ) { switch ( j ) { case 0 : case 1 : return ( c == END_OF_INPUT ) ? output . toByteArray ( ) : null ; case 2 : if ( c == END_OF_INPUT ) { return checkNoTrailingAndReturn ( output , in , pos [ 0 ] , inLength ) ; } pos [ 0 ] ++ ; c = getNextByte ( in , pos , inLength ) ; if ( c == END_OF_INPUT ) { return checkNoTrailingAndReturn ( output , in , pos [ 0 ] , inLength ) ; } if ( c == PAD_AS_BYTE ) { byteTripletAsInt >>= 4 ; output . write ( byteTripletAsInt ) ; return checkNoTrailingAndReturn ( output , in , pos [ 0 ] , inLength ) ; } return null ; case 3 : if ( c == PAD_AS_BYTE ) { byteTripletAsInt >>= 2 ; output . write ( byteTripletAsInt > > 8 ) ; output . write ( byteTripletAsInt & 0xff ) ; } return checkNoTrailingAndReturn ( output , in , pos [ 0 ] , inLength ) ; } } else { byteTripletAsInt <<= 6 ; byteTripletAsInt += ( c & 0xff ) ; pos [ 0 ] ++ ; } } output . write ( byteTripletAsInt > > 16 ) ; output . write ( ( byteTripletAsInt > > 8 ) & 0xff ) ; output . write ( byteTripletAsInt & 0xff ) ; } return checkNoTrailingAndReturn ( output , in , pos [ 0 ] , inLength ) ; } catch ( InvalidBase64ByteException e ) { return null ; } }
decodes the input from position 0 ( inclusive ) to len ( exclusive ) .
