common/src/main/java/HTTPClient/Codecs.java
/**
     * TBD! How to return file name and mode?
     *
     * @param rdr the reader from which to read and decode the data
     * @exception ParseException if either the "begin" or "end" line are not
     *                           found, or the "begin" is incorrect
     * @exception IOException if the <var>rdr</var> throws an IOException
     */
TBD. How to return file name and mode.
TBD . How to return file name and mode .
private final static byte[] uudecode(BufferedReader rdr)
		throws ParseException, IOException
    {
	String line, file_name;
	int    file_mode;
	while ((line = rdr.readLine()) != null  &&  !line.startsWith("begin "))
	    ;
	if (line == null)
	    throw new ParseException("'begin' line not found");
	StringTokenizer tok = new StringTokenizer(line);
	tok.nextToken();		
	try				
	    { file_mode = Integer.parseInt(tok.nextToken(), 8); }
	catch (Exception e)
	    { throw new ParseException("Invalid mode on line: " + line); }
	try				
	    { file_name = tok.nextToken(); }
	catch (java.util.NoSuchElementException e)
	    { throw new ParseException("No file name found on line: " + line); }
	byte[] body = new byte[1000];
	int    off  = 0;
	while ((line = rdr.readLine()) != null  &&  !line.equals("end"))
	{
	    byte[] tmp = uudecode(line.toCharArray());
	    if (off + tmp.length > body.length)
		body = Util.resizeArray(body, off+1000);
	    System.arraycopy(tmp, 0, body, off, tmp.length);
	    off += tmp.length;
	}
	if (line == null)
	    throw new ParseException("'end' line not found");
	return Util.resizeArray(body, off);
    }
private final static byte [ ] uudecode ( BufferedReader rdr ) throws ParseException , IOException { String line , file_name ; int file_mode ; while ( ( line = rdr . readLine ( ) ) != null && ! line . startsWith ( "begin " ) ) ; if ( line == null ) throw new ParseException ( "'begin' line not found" ) ; StringTokenizer tok = new StringTokenizer ( line ) ; tok . nextToken ( ) ; try { file_mode = Integer . parseInt ( tok . nextToken ( ) , 8 ) ; } catch ( Exception e ) { throw new ParseException ( "Invalid mode on line: " + line ) ; } try { file_name = tok . nextToken ( ) ; } catch ( java . util . NoSuchElementException e ) { throw new ParseException ( "No file name found on line: " + line ) ; } byte [ ] body = new byte [ 1000 ] ; int off = 0 ; while ( ( line = rdr . readLine ( ) ) != null && ! line . equals ( "end" ) ) { byte [ ] tmp = uudecode ( line . toCharArray ( ) ) ; if ( off + tmp . length > body . length ) body = Util . resizeArray ( body , off + 1000 ) ; System . arraycopy ( tmp , 0 , body , off , tmp . length ) ; off += tmp . length ; } if ( line == null ) throw new ParseException ( "'end' line not found" ) ; return Util . resizeArray ( body , off ) ; }
TBD!
TBD!
// search for beginning // parse 'begin' line // throw away 'begin' // extract mode // extract name // read and parse body