Example usage for org.eclipse.jgit.util TemporaryBuffer.Heap write

List of usage examples for org.eclipse.jgit.util TemporaryBuffer.Heap write

Introduction

In this page you can find the example usage for org.eclipse.jgit.util TemporaryBuffer.Heap write.

Prototype

@Override
public void write(int b) throws IOException 

Source Link

Usage

From source file:com.google.gerrit.httpd.restapi.RestApiServlet.java

License:Apache License

public static void replyJson(@Nullable HttpServletRequest req, HttpServletResponse res,
        Multimap<String, String> config, Object result) throws IOException {
    TemporaryBuffer.Heap buf = heap(HEAP_EST_SIZE, Integer.MAX_VALUE);
    buf.write(JSON_MAGIC);
    Writer w = new BufferedWriter(new OutputStreamWriter(buf, UTF_8));
    Gson gson = newGson(config, req);// w ww  .j ava 2s.  co m
    if (result instanceof JsonElement) {
        gson.toJson((JsonElement) result, w);
    } else {
        gson.toJson(result, w);
    }
    w.write('\n');
    w.flush();
    replyBinaryResult(req, res,
            asBinaryResult(buf).setContentType(JSON_TYPE).setCharacterEncoding(UTF_8.name()));
}

From source file:com.google.gerrit.httpd.restapi.RestApiServlet.java

License:Apache License

private static BinaryResult stackJsonString(HttpServletResponse res, final BinaryResult src)
        throws IOException {
    TemporaryBuffer.Heap buf = heap(HEAP_EST_SIZE, Integer.MAX_VALUE);
    buf.write(JSON_MAGIC);
    try (Writer w = new BufferedWriter(new OutputStreamWriter(buf, UTF_8));
            JsonWriter json = new JsonWriter(w)) {
        json.setLenient(true);//w  w  w. j a  v a2 s .c om
        json.setHtmlSafe(true);
        json.value(src.asString());
        w.write('\n');
    }
    res.setHeader("X-FYI-Content-Encoding", "json");
    res.setHeader("X-FYI-Content-Type", src.getContentType());
    return asBinaryResult(buf).setContentType(JSON_TYPE).setCharacterEncoding(UTF_8.name());
}