cvs commit: jakarta-tomcat-connectors/webapp/java WarpResponse.java

2001-07-19 Thread pier

pier01/07/19 16:35:56

  Added:   webapp/java WarpResponse.java
  Log:
  Re-enabling WarpResponse
  
  Revision  ChangesPath
  1.5   +139 -131  jakarta-tomcat-connectors/webapp/java/WarpResponse.java
  
  
  
  



cvs commit: jakarta-tomcat-connectors/webapp/java WarpResponse.java

2001-07-19 Thread pier

pier01/07/19 19:34:42

  Modified:webapp/java WarpResponse.java
  Log:
  Response handles the finishResponse() method correctly, now.
  The outputStream instance is recycled between requests.
  
  Revision  ChangesPath
  1.6   +97 -17jakarta-tomcat-connectors/webapp/java/WarpResponse.java
  
  Index: WarpResponse.java
  ===
  RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/java/WarpResponse.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WarpResponse.java 2001/07/19 23:35:56 1.5
  +++ WarpResponse.java 2001/07/20 02:34:41 1.6
  @@ -84,36 +84,75 @@
   import org.apache.catalina.util.RequestUtil;
   
   public class WarpResponse extends HttpResponseBase {
  +/** The local stream */
  +private Stream localstream;
  +/** The packet used for processing headers */
   private WarpPacket packet;
  +/** The connection to which we are associated */
   private WarpConnection connection;
   
  +/**
  + * Create a new instance of a codeWarpResponse/code.
  + */
   public WarpResponse() {
   super();
  -recycle();
  +// A WarpResponse is _always_ associated with a Stream
  +this.localstream=new Stream(this);
  +this.setStream(localstream);
   }
   
  +/**
  + * Recycle this codeWarpResponse/code instance.
  + */
   public void recycle() {
  +// Recycle our parent
   super.recycle();
  -this.setStream(new Stream(this));
  +// Recycle the stream
  +this.localstream.recycle();
  +// Tell the parent that a stream is already in use.
  +this.setStream(localstream);
   }
   
  +/**
  + * Set the codeWarpPacket/code instance used to process headers.
  + */
   public void setPacket(WarpPacket packet) {
   this.packet=packet;
   }
   
  +/**
  + * Return the codeWarpPacket/code instance used to process headers.
  + */
   public WarpPacket getPacket() {
   return(this.packet);
   }
  -
  +
  +/**
  + * Associate this codeWarpResponse/code instance with a specific
  + * codeWarpConnection/code instance.
  + */
   public void setConnection(WarpConnection connection) {
   this.connection=connection;
   }
   
  +/**
  + * Return the codeWarpConnection/code associated this instance of
  + * codeWarpResponse/code.
  + */
   public WarpConnection getConnection() {
   return(this.connection);
   }
   
   /**
  + * Flush output and finish.
  + */
  +public void finishResponse()
  +throws IOException {
  +super.finishResponse();
  +this.localstream.finish();
  +}
  +
  +/**
* Send the HTTP response headers, if this has not already occurred.
*/
   protected void sendHeaders() throws IOException {
  @@ -205,38 +244,79 @@
   
   committed = true;
   }
  -
  -private class Stream extends OutputStream {
  -private WarpConnection connection;
  -private WarpPacket packet;
  -
  -private Stream(WarpResponse response) {
  +
  +/** 
  + * The codeOutputStream/code that will handle all response body
  + * transmission.
  + */
  +protected class Stream extends OutputStream {
  +/** The response associated with this stream instance. */
  +private WarpResponse response=null;
  +/** The packet used by this stream instance. */
  +private WarpPacket packet=null;
  +/** Wether codeclose()/code was called or not. */
  +private boolean closed=false;
  +
  +/**
  + * Construct a new instance of a codeWarpResponse.Stream/code
  + * associated with a parent codeWarpResponse/code.
  + */
  +protected Stream(WarpResponse response) {
   super();
  -this.connection=response.getConnection();
  +this.response=response;
   this.packet=new WarpPacket();
  -packet.setType(Constants.TYPE_RES_BODY);
   }
   
  +/**
  + * Write one byte of data to the codeWarpPacket/code nested
  + * within this codeWarpResponse.Stream/code. All data is buffered
  + * until the codeflush()/code or codeclose()/code method is
  + * not called.
  + */
   public void write(int b) 
   throws IOException {
  +if (closed) throw new IOException(Stream closed);
   packet.buffer[packet.size++]=(byte)b;
   }
   
  +/**
  + * Flush the current packet to the WARP client.
  + */
   public void flush()
   throws IOException {
  -this.connection.send(packet);
  -packet.reset();
  +if (closed) throw new