From: Fredrik Tolf Date: Mon, 12 Oct 2009 20:47:20 +0000 (+0200) Subject: Made the buffered response resettable. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=c35d6760bbadced0cee2aa1bae788dee8aff23ef;p=jsvc.git Made the buffered response resettable. --- diff --git a/src/dolda/jsvc/ResettableRequest.java b/src/dolda/jsvc/ResettableRequest.java new file mode 100644 index 0000000..c202243 --- /dev/null +++ b/src/dolda/jsvc/ResettableRequest.java @@ -0,0 +1,6 @@ +package dolda.jsvc; + +public interface ResettableRequest extends Request { + public boolean canreset(); + public void reset(); +} diff --git a/src/dolda/jsvc/util/ResponseBuffer.java b/src/dolda/jsvc/util/ResponseBuffer.java index 7c57608..83e91cd 100644 --- a/src/dolda/jsvc/util/ResponseBuffer.java +++ b/src/dolda/jsvc/util/ResponseBuffer.java @@ -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 headers = new HeaderTreeMap() { - protected void modified() { - ckflush(); - } - }; + private MultiMap 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(); }