private void encode(OutputStream out,int[] data,int len) throws IOException {
  int d1, d2, d3;
switch (len) {
case 0:
    break;
case 1:
  d1=data[0];
out.write(encodingTable[(d1 >>> 2) & 0x3f]);
out.write(encodingTable[(d1 << 4) & 0x3f]);
out.write('=');
out.write('=');
break;
case 2:
d1=data[0];
d2=data[1];
out.write(encodingTable[(d1 >>> 2) & 0x3f]);
out.write(encodingTable[((d1 << 4) | (d2 >>> 4)) & 0x3f]);
out.write(encodingTable[(d2 << 2) & 0x3f]);
out.write('=');
break;
case 3:
d1=data[0];
d2=data[1];
d3=data[2];
out.write(encodingTable[(d1 >>> 2) & 0x3f]);
out.write(encodingTable[((d1 << 4) | (d2 >>> 4)) & 0x3f]);
out.write(encodingTable[((d2 << 2) | (d3 >>> 6)) & 0x3f]);
out.write(encodingTable[d3 & 0x3f]);
break;
default :
throw new IOException("unknown length in encode");
}
}

private void encode ( OutputStream out , int [ ] data , int len ) throws IOException { int d1 , d2 , d3 ; switch ( len ) { case 0 : break ; case 1 : d1 = data [ 0 ] ; out . write ( encodingTable [ ( d1 > > > 2 ) & 0x3f ] ) ; out . write ( encodingTable [ ( d1 << 4 ) & 0x3f ] ) ; out . write ( '=' ) ; out . write ( '=' ) ; break ; case 2 : d1 = data [ 0 ] ; d2 = data [ 1 ] ; out . write ( encodingTable [ ( d1 > > > 2 ) & 0x3f ] ) ; out . write ( encodingTable [ ( ( d1 << 4 ) | ( d2 > > > 4 ) ) & 0x3f ] ) ; out . write ( encodingTable [ ( d2 << 2 ) & 0x3f ] ) ; out . write ( '=' ) ; break ; case 3 : d1 = data [ 0 ] ; d2 = data [ 1 ] ; d3 = data [ 2 ] ; out . write ( encodingTable [ ( d1 > > > 2 ) & 0x3f ] ) ; out . write ( encodingTable [ ( ( d1 << 4 ) | ( d2 > > > 4 ) ) & 0x3f ] ) ; out . write ( encodingTable [ ( ( d2 << 2 ) | ( d3 > > > 6 ) ) & 0x3f ] ) ; out . write ( encodingTable [ d3 & 0x3f ] ) ; break ; default : throw new IOException ( "unknown length in encode" ) ; } }
encode the input data producing a base 64 encoded byte array .
