diff src/goodjava/webserver/ResponseOutputStream.java @ 1402:27efb1fcbcb5

move luan.lib to goodjava
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 17 Sep 2019 01:35:01 -0400
parents src/luan/lib/webserver/ResponseOutputStream.java@643cf1c37723
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/goodjava/webserver/ResponseOutputStream.java	Tue Sep 17 01:35:01 2019 -0400
@@ -0,0 +1,22 @@
+package goodjava.webserver;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+
+// plenty of room for improvement
+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.body = new Response.Body( size, new ByteArrayInputStream(buf,0,size) );
+	}
+}