common/src/main/java/HTTPClient/HttpOutputStream.java
/**
     * Closes the stream and causes the data to be sent if it has not already
     * been done so. This method <strong>must</strong> be invoked when all
     * data has been written.
     *
     * @exception IOException if any exception is thrown by the underlying
     *            socket, or if too few bytes were written.
     * @exception IllegalAccessError if this stream has not been associated
     *            with a request yet.
     */
Closes the stream and causes the data to be sent if it has not already
been done so. This method must be invoked when all
data has been written.

@exception IOException if any exception is thrown by the underlying
socket, or if too few bytes were written.
@exception IllegalAccessError if this stream has not been associated
with a request yet.
Closes the stream and causes the data to be sent if it has not already been done so . This method must be invoked when all data has been written . @exception IOException if any exception is thrown by the underlying socket or if too few bytes were written . @exception IllegalAccessError if this stream has not been associated with a request yet .
public synchronized void close()  throws IOException, IllegalAccessError
    {
	if (req == null)
	    throw new IllegalAccessError("Stream not associated with a request");
	if (ignore) return;
	if (bos != null)
	{
	    req.setData(bos.toByteArray());
	    req.setStream(null);
	    if (trailers.length > 0)
	    {
		NVPair[] hdrs = req.getHeaders();
		int len = hdrs.length;
		for (int idx=0; idx<len; idx++)
		{
		    if (hdrs[idx].getName().equalsIgnoreCase("Trailer"))
		    {
			System.arraycopy(hdrs, idx+1, hdrs, idx, len-idx-1);
			len--;
		    }
		}
		hdrs = Util.resizeArray(hdrs, len+trailers.length);
		System.arraycopy(trailers, 0, hdrs, len, trailers.length);
		req.setHeaders(hdrs);
	    }
	    Log.write(Log.CONN, "OutS:  Sending request");
	    try
		{ resp = req.getConnection().sendRequest(req, con_to); }
	    catch (ModuleException me)
		{ throw new IOException(me.toString()); }
	    notify();
	}
	else
	{
	    if (rcvd < length)
	    {
		IOException ioe =
		    new IOException("Premature close: only " + rcvd +
				    " bytes written instead of the " +
				    "expected " + length);
		req.getConnection().closeDemux(ioe, false);
		req.getConnection().outputFinished();
		throw ioe;
	    }
	    try
	    {
		if (length == -1)
		{
		    if (Log.isEnabled(Log.CONN)  &&  trailers.length > 0)
		    {
			Log.write(Log.CONN, "OutS:  Sending trailers:");
			for (int idx=0; idx<trailers.length; idx++)
			    Log.write(Log.CONN, "       " +
						trailers[idx].getName() + ": " +
						trailers[idx].getValue());
		    }
		    os.write(Codecs.chunkedEncode(null, 0, 0, trailers, true));
		}
		os.flush();
		Log.write(Log.CONN, "OutS:  All data sent");
	    }
	    catch (IOException ioe)
	    {
		req.getConnection().closeDemux(ioe, true);
		throw ioe;
	    }
	    finally
	    {
		req.getConnection().outputFinished();
	    }
	}
    }
public synchronized void close ( ) throws IOException , IllegalAccessError { if ( req == null ) throw new IllegalAccessError ( "Stream not associated with a request" ) ; if ( ignore ) return ; if ( bos != null ) { req . setData ( bos . toByteArray ( ) ) ; req . setStream ( null ) ; if ( trailers . length > 0 ) { NVPair [ ] hdrs = req . getHeaders ( ) ; int len = hdrs . length ; for ( int idx = 0 ; idx < len ; idx ++ ) { if ( hdrs [ idx ] . getName ( ) . equalsIgnoreCase ( "Trailer" ) ) { System . arraycopy ( hdrs , idx + 1 , hdrs , idx , len - idx - 1 ) ; len -- ; } } hdrs = Util . resizeArray ( hdrs , len + trailers . length ) ; System . arraycopy ( trailers , 0 , hdrs , len , trailers . length ) ; req . setHeaders ( hdrs ) ; } Log . write ( Log . CONN , "OutS:  Sending request" ) ; try { resp = req . getConnection ( ) . sendRequest ( req , con_to ) ; } catch ( ModuleException me ) { throw new IOException ( me . toString ( ) ) ; } notify ( ) ; } else { if ( rcvd < length ) { IOException ioe = new IOException ( "Premature close: only " + rcvd + " bytes written instead of the " + "expected " + length ) ; req . getConnection ( ) . closeDemux ( ioe , false ) ; req . getConnection ( ) . outputFinished ( ) ; throw ioe ; } try { if ( length == - 1 ) { if ( Log . isEnabled ( Log . CONN ) && trailers . length > 0 ) { Log . write ( Log . CONN , "OutS:  Sending trailers:" ) ; for ( int idx = 0 ; idx < trailers . length ; idx ++ ) Log . write ( Log . CONN , "       " + trailers [ idx ] . getName ( ) + ": " + trailers [ idx ] . getValue ( ) ) ; } os . write ( Codecs . chunkedEncode ( null , 0 , 0 , trailers , true ) ) ; } os . flush ( ) ; Log . write ( Log . CONN , "OutS:  All data sent" ) ; } catch ( IOException ioe ) { req . getConnection ( ) . closeDemux ( ioe , true ) ; throw ioe ; } finally { req . getConnection ( ) . outputFinished ( ) ; } } }
Closes the stream and causes the data to be sent if it has not already
 been done so.
Closes the stream and causes the data to be sent if it has not already been done so .
// remove any Trailer header field // add the trailers to the headers