common/src/main/java/HTTPClient/Codecs.java
/**
     * This method encodes the given byte[] using the unix uuencode
     * encding. The output is split into lines starting with the encoded
     * number of encoded octets in the line and ending with a newline.
     * No line is longer than 45 octets (60 characters), not including
     * length and newline.
     *
     * <P><em>Note:</em> just the raw data is encoded; no 'begin' and 'end'
     * lines are added as is done by the unix <code>uuencode</code> utility.
     *
     * @param  data the data
     * @return the uuencoded <var>data</var>
     */
This method encodes the given byte[] using the unix uuencode
encding. The output is split into lines starting with the encoded
number of encoded octets in the line and ending with a newline.
No line is longer than 45 octets (60 characters), not including
length and newline.

Note: just the raw data is encoded; no 'begin' and 'end'
lines are added as is done by the unix uuencode utility.


This method encodes the given byte [] using the unix uuencode encding . The output is split into lines starting with the encoded number of encoded octets in the line and ending with a newline . No line is longer than 45 octets ( 60 characters ) not including length and newline . Note : just the raw data is encoded ; no ' begin ' and ' end ' lines are added as is done by the unix uuencode utility .
public final static char[] uuencode(byte[] data)
    {
	if (data == null)      return  null;
	if (data.length == 0)  return  new char[0];
	int line_len = 45;	
	int sidx, didx;
	char nl[]   = System.getProperty("line.separator", "\n").toCharArray(),
	     dest[] = new char[(data.length+2)/3*4 +
			    ((data.length+line_len-1)/line_len)*(nl.length+1)];
	for (sidx=0, didx=0; sidx+line_len < data.length; )
	{
	    dest[didx++] = UUEncMap[line_len];
	    for (int end = sidx+line_len; sidx < end; sidx += 3)
	    {
		dest[didx++] = UUEncMap[(data[sidx] >>> 2) & 077];
		dest[didx++] = UUEncMap[(data[sidx+1] >>> 4) & 017 |
					    (data[sidx] << 4) & 077];
		dest[didx++] = UUEncMap[(data[sidx+2] >>> 6) & 003 |
					    (data[sidx+1] << 2) & 077];
		dest[didx++] = UUEncMap[data[sidx+2] & 077];
	    }
	    for (int idx=0; idx<nl.length; idx++)  dest[didx++] = nl[idx];
	}
	dest[didx++] = UUEncMap[data.length-sidx];
	for (; sidx+2 < data.length; sidx += 3)
	{
	    dest[didx++] = UUEncMap[(data[sidx] >>> 2) & 077];
	    dest[didx++] = UUEncMap[(data[sidx+1] >>> 4) & 017 |
					(data[sidx] << 4) & 077];
	    dest[didx++] = UUEncMap[(data[sidx+2] >>> 6) & 003 |
					(data[sidx+1] << 2) & 077];
	    dest[didx++] = UUEncMap[data[sidx+2] & 077];
	}
	if (sidx < data.length-1)
	{
	    dest[didx++] = UUEncMap[(data[sidx] >>> 2) & 077];
	    dest[didx++] = UUEncMap[(data[sidx+1] >>> 4) & 017 |
					(data[sidx] << 4) & 077];
	    dest[didx++] = UUEncMap[(data[sidx+1] << 2) & 077];
	    dest[didx++] = UUEncMap[0];
	}
	else if (sidx < data.length)
	{
	    dest[didx++] = UUEncMap[(data[sidx] >>> 2) & 077];
	    dest[didx++] = UUEncMap[(data[sidx] << 4) & 077];
	    dest[didx++] = UUEncMap[0];
	    dest[didx++] = UUEncMap[0];
	}
	for (int idx=0; idx<nl.length; idx++)  dest[didx++] = nl[idx];
	if (didx != dest.length)
	    throw new Error("Calculated "+dest.length+" chars but wrote "+didx+" chars!");
	return dest;
    }
public final static char [ ] uuencode ( byte [ ] data ) { if ( data == null ) return null ; if ( data . length == 0 ) return new char [ 0 ] ; int line_len = 45 ; int sidx , didx ; char nl [ ] = System . getProperty ( "line.separator" , "\n" ) . toCharArray ( ) , dest [ ] = new char [ ( data . length + 2 ) / 3 * 4 + ( ( data . length + line_len - 1 ) / line_len ) * ( nl . length + 1 ) ] ; for ( sidx = 0 , didx = 0 ; sidx + line_len < data . length ; ) { dest [ didx ++ ] = UUEncMap [ line_len ] ; for ( int end = sidx + line_len ; sidx < end ; sidx += 3 ) { dest [ didx ++ ] = UUEncMap [ ( data [ sidx ] >>> 2 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ ( data [ sidx + 1 ] >>> 4 ) & 017 | ( data [ sidx ] << 4 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ ( data [ sidx + 2 ] >>> 6 ) & 003 | ( data [ sidx + 1 ] << 2 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ data [ sidx + 2 ] & 077 ] ; } for ( int idx = 0 ; idx < nl . length ; idx ++ ) dest [ didx ++ ] = nl [ idx ] ; } dest [ didx ++ ] = UUEncMap [ data . length - sidx ] ; for ( ; sidx + 2 < data . length ; sidx += 3 ) { dest [ didx ++ ] = UUEncMap [ ( data [ sidx ] >>> 2 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ ( data [ sidx + 1 ] >>> 4 ) & 017 | ( data [ sidx ] << 4 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ ( data [ sidx + 2 ] >>> 6 ) & 003 | ( data [ sidx + 1 ] << 2 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ data [ sidx + 2 ] & 077 ] ; } if ( sidx < data . length - 1 ) { dest [ didx ++ ] = UUEncMap [ ( data [ sidx ] >>> 2 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ ( data [ sidx + 1 ] >>> 4 ) & 017 | ( data [ sidx ] << 4 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ ( data [ sidx + 1 ] << 2 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ 0 ] ; } else if ( sidx < data . length ) { dest [ didx ++ ] = UUEncMap [ ( data [ sidx ] >>> 2 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ ( data [ sidx ] << 4 ) & 077 ] ; dest [ didx ++ ] = UUEncMap [ 0 ] ; dest [ didx ++ ] = UUEncMap [ 0 ] ; } for ( int idx = 0 ; idx < nl . length ; idx ++ ) dest [ didx ++ ] = nl [ idx ] ; if ( didx != dest . length ) throw new Error ( "Calculated " + dest . length + " chars but wrote " + didx + " chars!" ) ; return dest ; }
This method encodes the given byte[] using the unix uuencode
 encding.
This method encodes the given byte [] using the unix uuencode encding .
// line length, in octets // split into lines, adding line-length and line terminator // line length // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion // line terminator // last line // line length // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion // line terminator // sanity check