Made the buffered response resettable.
authorFredrik Tolf <fredrik@dolda2000.com>
Mon, 12 Oct 2009 20:47:20 +0000 (22:47 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Mon, 12 Oct 2009 20:47:20 +0000 (22:47 +0200)
src/dolda/jsvc/ResettableRequest.java [new file with mode: 0644]
src/dolda/jsvc/util/ResponseBuffer.java

diff --git a/src/dolda/jsvc/ResettableRequest.java b/src/dolda/jsvc/ResettableRequest.java
new file mode 100644 (file)
index 0000000..c202243
--- /dev/null
@@ -0,0 +1,6 @@
+package dolda.jsvc;
+
+public interface ResettableRequest extends Request {
+    public boolean canreset();
+    public void reset();
+}
index 7c57608..83e91cd 100644 (file)
@@ -4,16 +4,27 @@ import dolda.jsvc.*;
 import java.io.*;
 import java.util.*;
 
-public abstract class ResponseBuffer implements Request {
+public abstract class ResponseBuffer implements ResettableRequest {
     private boolean flushed = false;
     private int respcode = -1;
     private String resptext = null;
     private OutputStream out = null, wrapout = null;
-    private MultiMap<String, String> headers = new HeaderTreeMap() {
-           protected void modified() {
-               ckflush();
-           }
-    };
+    private MultiMap<String, String> headers;
+    
+    public ResponseBuffer() {
+       init();
+    }
+
+    private void init() {
+       ckflush();
+       wrapout = null;
+       respcode = -1;
+       headers = new HeaderTreeMap() {
+               protected void modified() {
+                   ckflush();
+               }
+           };
+    }
     
     private void ckflush() {
        if(flushed)
@@ -81,6 +92,14 @@ public abstract class ResponseBuffer implements Request {
        return(headers);
     }
     
+    public boolean canreset() {
+       return(!flushed);
+    }
+    
+    public void reset() {
+       init();
+    }
+    
     protected abstract void backflush();
     protected abstract OutputStream realoutput();
 }