static byte[] discardNonBase64(byte[] data){
  byte groomedData[]=new byte[data.length];
  int bytesCopied=0;
  for (int i=0; i < data.length; i++) {
    if (isBase64(data[i])) {
      groomedData[bytesCopied++]=data[i];
    }
  }
  byte packedData[]=new byte[bytesCopied];
  System.arraycopy(groomedData,0,packedData,0,bytesCopied);
  return packedData;
}

static byte [ ] discardNonBase64 ( byte [ ] data ) { byte groomedData [ ] = new byte [ data . length ] ; int bytesCopied = 0 ; for ( int i = 0 ; i < data . length ; i ++ ) { if ( isBase64 ( data [ i ] ) ) { groomedData [ bytesCopied ++ ] = data [ i ] ; } } byte packedData [ ] = new byte [ bytesCopied ] ; System . arraycopy ( groomedData , 0 , packedData , 0 , bytesCopied ) ; return packedData ; }
discards any characters outside of the base64 alphabet , per the requirements on page 25 of rfc 2045 - " any characters outside of the base64 alphabet are to be ignored in base64 encoded data . "
