-
Notifications
You must be signed in to change notification settings - Fork 3
/
ByteResponse.java
51 lines (41 loc) · 1.45 KB
/
ByteResponse.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package net.jonathangiles.tools.teenyhttpd.response;
import net.jonathangiles.tools.teenyhttpd.request.Request;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
public class ByteResponse extends Response {
final StatusCode statusCode;
final List<String> headers;
final byte[] body;
public ByteResponse(final Request request, final StatusCode statusCode) {
this(request, statusCode, Collections.emptyList());
}
public ByteResponse(final Request request, final StatusCode statusCode, final List<String> headers) {
this(request, statusCode, headers, null);
}
public ByteResponse(final Request request, final StatusCode statusCode, final byte[] body) {
this(request, statusCode, Collections.emptyList(), body);
}
public ByteResponse(final Request request, final StatusCode statusCode, final List<String> headers, final byte[] body) {
super(request);
this.statusCode = statusCode;
this.headers = headers;
this.body = body;
}
@Override
public StatusCode getStatusCode() {
return statusCode;
}
@Override
public List<String> getHeaders() {
return headers;
}
@Override
public void writeBody(BufferedOutputStream dataOut) throws IOException {
if (body != null) {
dataOut.write(body, 0, body.length);
dataOut.flush();
}
}
}