All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.iprogrammerr.bright.server.response.ContentResponse Maven / Gradle / Ivy

package com.iprogrammerr.bright.server.response;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.iprogrammerr.bright.server.header.Header;
import com.iprogrammerr.bright.server.header.template.ContentLengthHeader;
import com.iprogrammerr.bright.server.header.template.ContentTypeHeader;
import com.iprogrammerr.bright.server.response.body.ResponseBody;

public final class ContentResponse implements Response {

    private final int code;
    private final byte[] body;
    private final List
headers; public ContentResponse(int code, ResponseBody body) { this(code, body.type(), body.content(), new ArrayList<>()); } public ContentResponse(int code, ResponseBody body, Header... headers) { this(code, body.type(), body.content(), new ArrayList<>(Arrays.asList(headers))); } public ContentResponse(int code, ResponseBody body, List
headers) { this(code, body.type(), body.content(), headers); } public ContentResponse(int code, String textBody) { this(code, "text/plain", textBody.getBytes(), new ArrayList<>()); } public ContentResponse(int code, String contentType, byte[] body, List
headers) { this.code = code; this.body = body; this.headers = headers; this.headers.add(new ContentTypeHeader(contentType)); this.headers.add(new ContentLengthHeader(body.length)); } @Override public int code() { return code; } @Override public List
headers() { return headers; } @Override public boolean hasBody() { return true; } @Override public byte[] body() { return body; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy