Search in sources :

Example 1 with UTF8StreamWriter

use of org.elasticsearch.common.io.UTF8StreamWriter in project elasticsearch by elastic.

the class MustacheScriptEngineService method utf8StreamWriter.

/** If exists, reset and return, otherwise create, reset and return a writer.*/
private static UTF8StreamWriter utf8StreamWriter() {
    SoftReference<UTF8StreamWriter> ref = utf8StreamWriter.get();
    UTF8StreamWriter writer = (ref == null) ? null : ref.get();
    if (writer == null) {
        writer = new UTF8StreamWriter(1024 * 4);
        utf8StreamWriter.set(new SoftReference<>(writer));
    }
    writer.reset();
    return writer;
}
Also used : UTF8StreamWriter(org.elasticsearch.common.io.UTF8StreamWriter)

Example 2 with UTF8StreamWriter

use of org.elasticsearch.common.io.UTF8StreamWriter in project elasticsearch by elastic.

the class RestTable method buildTextPlainResponse.

public static RestResponse buildTextPlainResponse(Table table, RestChannel channel) throws IOException {
    RestRequest request = channel.request();
    boolean verbose = request.paramAsBoolean("v", false);
    List<DisplayHeader> headers = buildDisplayHeaders(table, request);
    int[] width = buildWidths(table, request, verbose, headers);
    BytesStreamOutput bytesOut = channel.bytesOutput();
    UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOut);
    int lastHeader = headers.size() - 1;
    if (verbose) {
        for (int col = 0; col < headers.size(); col++) {
            DisplayHeader header = headers.get(col);
            boolean isLastColumn = col == lastHeader;
            pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out, isLastColumn);
            if (!isLastColumn) {
                out.append(" ");
            }
        }
        out.append("\n");
    }
    List<Integer> rowOrder = getRowOrder(table, request);
    for (Integer row : rowOrder) {
        for (int col = 0; col < headers.size(); col++) {
            DisplayHeader header = headers.get(col);
            boolean isLastColumn = col == lastHeader;
            pad(table.getAsMap().get(header.name).get(row), width[col], request, out, isLastColumn);
            if (!isLastColumn) {
                out.append(" ");
            }
        }
        out.append("\n");
    }
    out.close();
    return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
}
Also used : Table(org.elasticsearch.common.Table) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) RestRequest(org.elasticsearch.rest.RestRequest) UTF8StreamWriter(org.elasticsearch.common.io.UTF8StreamWriter) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse)

Aggregations

UTF8StreamWriter (org.elasticsearch.common.io.UTF8StreamWriter)2 Table (org.elasticsearch.common.Table)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)1 RestRequest (org.elasticsearch.rest.RestRequest)1