public static String encodeLines(byte[] in,int iOff,int iLen,int lineLen,String lineSeparator){
  int blockLen=(lineLen * 3) / 4;
  if (blockLen <= 0)   throw new IllegalArgumentException();
  int lines=(iLen + blockLen - 1) / blockLen;
  int bufLen=((iLen + 2) / 3) * 4 + lines * lineSeparator.length();
  StringBuilder buf=new StringBuilder(bufLen);
  int ip=0;
  while (ip < iLen) {
    int l=Math.min(iLen - ip,blockLen);
    buf.append(encode(in,iOff + ip,l));
    buf.append(lineSeparator);
    ip+=l;
  }
  return buf.toString();
}

public static String encodeLines ( byte [ ] in , int iOff , int iLen , int lineLen , String lineSeparator ) { int blockLen = ( lineLen * 3 ) / 4 ; if ( blockLen <= 0 ) throw new IllegalArgumentException ( ) ; int lines = ( iLen + blockLen - 1 ) / blockLen ; int bufLen = ( ( iLen + 2 ) / 3 ) * 4 + lines * lineSeparator . length ( ) ; StringBuilder buf = new StringBuilder ( bufLen ) ; int ip = 0 ; while ( ip < iLen ) { int l = Math . min ( iLen - ip , blockLen ) ; buf . append ( encode ( in , iOff + ip , l ) ) ; buf . append ( lineSeparator ) ; ip += l ; } return buf . toString ( ) ; }
encodes a byte array into base 64 format and breaks the output into lines .
