aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/handler/metrics/JsonResponse.java
blob: c55d93f7b2aedf24d49ff68c6134fa627c9caf9c (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.handler.metrics;

import com.yahoo.container.jdisc.HttpResponse;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;

/**
 * @author gjoranv
 */
public class JsonResponse extends HttpResponse {

    private final byte[] data;

    public JsonResponse(int code, String data) {
        super(code);
        this.data = data.getBytes(Charset.forName(DEFAULT_CHARACTER_ENCODING));
    }

    @Override
    public String getContentType() {
        return "application/json";
    }

    @Override
    public void render(OutputStream outputStream) throws IOException {
        outputStream.write(data);
    }

}