common/src/main/java/HTTPClient/Codecs.java
/**
     * Decodes chunked data. The chunks are read from an InputStream, which
     * is assumed to be correctly positioned. Use 'xxx instanceof byte[]'
     * and 'xxx instanceof NVPair[]' to determine if this was data or the
     * last chunk.
     *
     * @param  input  the stream from which to read the next chunk.
     * @return If this was a data chunk then it returns a byte[]; else
     *         it's the footer and it returns a NVPair[] containing the
     *         footers.
     * @exception ParseException If any exception during parsing occured.
     * @exception IOException    If any exception during reading occured.
     */
Decodes chunked data. The chunks are read from an InputStream, which
is assumed to be correctly positioned. Use 'xxx instanceof byte[]'
and 'xxx instanceof NVPair[]' to determine if this was data or the
last chunk.

@param  input  the stream from which to read the next chunk.
@return If this was a data chunk then it returns a byte[]; else
it's the footer and it returns a NVPair[] containing the
footers.
@exception ParseException If any exception during parsing occured.
@exception IOException    If any exception during reading occured.
Decodes chunked data . The chunks are read from an InputStream which is assumed to be correctly positioned . Use ' xxx instanceof byte [] ' and ' xxx instanceof NVPair [] ' to determine if this was data or the last chunk . @param input the stream from which to read the next chunk . @return If this was a data chunk then it returns a byte [] ; else it ' s the footer and it returns a NVPair [] containing the footers . @exception ParseException If any exception during parsing occured . @exception IOException If any exception during reading occured .
public final static Object chunkedDecode(InputStream input)
	    throws ParseException, IOException
    {
	long clen = getChunkLength(input);
	if (clen > Integer.MAX_VALUE)		
	    throw new ParseException("Can't deal with chunk lengths greater " +
				     "Integer.MAX_VALUE: " + clen + " > " +
				     Integer.MAX_VALUE);
	if (clen > 0)			
	{
	    byte[] res = new byte[(int) clen];
	    int off = 0, len = 0;
	    while (len != -1  &&  off < res.length)
	    {
		len  = input.read(res, off, res.length-off);
		off += len;
	    }
	    if (len == -1)
		throw new ParseException("Premature EOF while reading chunk;" +
					 "Expected: "+res.length+" Bytes, " +
					 "Received: "+(off+1)+" Bytes");
	    input.read();	
	    input.read();	
	    return res;
	}
	else				
	{
	    NVPair[] res = new NVPair[0];
	    BufferedReader reader = new BufferedReader(new InputStreamReader(input, "8859_1"));
	    String line;
	    while ((line = reader.readLine()) != null  &&  line.length() > 0)
	    {
		int colon = line.indexOf(':');
		if (colon == -1)
		    throw new ParseException("Error in Footer format: no "+
					     "':' found in '" + line + "'");
		res = Util.resizeArray(res, res.length+1);
		res[res.length-1] = new NVPair(line.substring(0, colon).trim(),
					       line.substring(colon+1).trim());
	    }
	    return res;
	}
    }
public final static Object chunkedDecode ( InputStream input ) throws ParseException , IOException { long clen = getChunkLength ( input ) ; if ( clen > Integer . MAX_VALUE ) throw new ParseException ( "Can't deal with chunk lengths greater " + "Integer.MAX_VALUE: " + clen + " > " + Integer . MAX_VALUE ) ; if ( clen > 0 ) { byte [ ] res = new byte [ ( int ) clen ] ; int off = 0 , len = 0 ; while ( len != - 1 && off < res . length ) { len = input . read ( res , off , res . length - off ) ; off += len ; } if ( len == - 1 ) throw new ParseException ( "Premature EOF while reading chunk;" + "Expected: " + res . length + " Bytes, " + "Received: " + ( off + 1 ) + " Bytes" ) ; input . read ( ) ; input . read ( ) ; return res ; } else { NVPair [ ] res = new NVPair [ 0 ] ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( input , "8859_1" ) ) ; String line ; while ( ( line = reader . readLine ( ) ) != null && line . length ( ) > 0 ) { int colon = line . indexOf ( ':' ) ; if ( colon == - 1 ) throw new ParseException ( "Error in Footer format: no " + "':' found in '" + line + "'" ) ; res = Util . resizeArray ( res , res . length + 1 ) ; res [ res . length - 1 ] = new NVPair ( line . substring ( 0 , colon ) . trim ( ) , line . substring ( colon + 1 ) . trim ( ) ) ; } return res ; } }
Decodes chunked data.
Decodes chunked data .
// Huston, what the hell are you sending? // it's a chunk // CR // LF // it's the end // read and parse footer