1 package dolda.jsvc.util;
7 public abstract class ResponseBuffer implements ResettableRequest {
8 private boolean flushed = false;
9 protected int respcode = -1;
10 protected String resptext = null;
11 private OutputStream out = null, wrapout = null;
12 private MultiMap<String, String> headers;
14 public ResponseBuffer() {
22 headers = new HeaderTreeMap() {
23 protected void modified() {
29 private void ckflush() {
31 throw(new IllegalStateException("Response has been flushed; header information cannot be modified"));
34 private void flush() {
46 private class FlushStream extends OutputStream {
47 private FlushStream() {
50 public void flush() throws IOException {
51 ResponseBuffer.this.flush();
55 public void close() throws IOException {
60 public void write(int b) throws IOException {
61 ResponseBuffer.this.flush();
65 public void write(byte[] b) throws IOException {
66 write(b, 0, b.length);
69 public void write(byte[] b, int off, int len) throws IOException {
70 ResponseBuffer.this.flush();
71 out.write(b, off, len);
75 public OutputStream output() {
77 wrapout = new BufferedOutputStream(new FlushStream(), 16384);
81 public void status(int code) {
82 status(code, Misc.statustext(code));
85 public void status(int code, String text) {
91 public MultiMap<String, String> outheaders() {
95 public boolean canreset() {
103 protected abstract void backflush();
104 protected abstract OutputStream realoutput();