private HttpResponse completeResponse() {
        try {
            if (responseWriter != null) {
                // response stream has been open, let's flush the remaining bytes
                if (contentStream.hasWritten()) {
                    contentStream.flush();
                }
                responseWriter.close();
                return responseWriter;
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        // response stream has not yet been open, lets send the data right away
        final HttpData contentData;
        if (errorMessage != null) {
            contentData = HttpData.ofUtf8(errorMessage);
        } else if (contentStream.hasWritten()) {
            final ByteBuf writtenBytes = contentStream.dumpWrittenAndClose();
            contentData = HttpData.wrap(writtenBytes);
        } else {
            contentData = HttpData.empty();
        }
        final ResponseHeaders responseHeaders = responseHeaders();
        final HttpResponse response =
                contentData.isEmpty() ? HttpResponse.of(responseHeaders)
                                      : HttpResponse.of(responseHeaders, contentData);
        committed = true;
        return response;
    }
Implements {@link org.jboss.resteasy.spi.HttpResponse}.
resteasy/src/main/java/com/linecorp/armeria/server/resteasy/ResteasyHttpResponseImpl.java