view src/goodjava/webserver/ResponseOutputStream.java @ 2008:bba3e529e346 default tip

chunked encoding
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 27 Aug 2025 01:14:17 -0600
parents 27efb1fcbcb5
children
line wrap: on
line source

package goodjava.webserver;

import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;


public class ResponseOutputStream extends ByteArrayOutputStream {
	private final Response response;

	public ResponseOutputStream(Response response) {
		if(response==null) throw new NullPointerException();
		this.response = response;
	}

	@Override public void close() throws IOException {
		super.close();
		int size = size();
		response.headers.put("Content-Length",Long.toString(size));
		response.body = new ByteArrayInputStream(buf,0,size);
	}
}