Search in sources :

Example 6 with AutoBuffer

use of water.AutoBuffer in project h2o-3 by h2oai.

the class BufferedStringTest method testWrite_impl.

@Test
public void testWrite_impl() throws Exception {
    final String source = "this is not a string";
    BufferedString sut = new BufferedString(source);
    assertArrayEquals(source.getBytes(), sut.getBuffer());
    AutoBuffer ab = new AutoBuffer();
    sut.write_impl(ab);
    final byte[] expected = ("" + source).getBytes();
    final byte[] actual = ab.buf();
    assertArrayEquals(expected, actual);
}
Also used : AutoBuffer(water.AutoBuffer) Test(org.junit.Test)

Example 7 with AutoBuffer

use of water.AutoBuffer in project h2o-2 by h2oai.

the class RequestBuilders method build.

/** Builds the HTML for the given response.
   *
   * This is the root of the HTML. Should display all what is needed, including
   * the status, timing, etc. Then call the recursive builders for the
   * response's JSON.
   */
protected String build(Response response) {
    StringBuilder sb = new StringBuilder();
    sb.append("<div class='container'>");
    sb.append("<div class='row-fluid'>");
    sb.append("<div class='span12'>");
    sb.append(buildJSONResponseBox(response));
    if (response._status == Response.Status.done)
        response.toJava(sb);
    sb.append(buildResponseHeader(response));
    Builder builder = response.getBuilderFor(ROOT_OBJECT);
    if (builder == null) {
        sb.append("<h3>" + name() + "</h3>");
        builder = OBJECT_BUILDER;
    }
    for (String h : response.getHeaders()) sb.append(h);
    if (response._response == null) {
        boolean done = response._req.toHTML(sb);
        if (!done) {
            JsonParser parser = new JsonParser();
            String json = new String(response._req.writeJSON(new AutoBuffer()).buf());
            JsonObject o = (JsonObject) parser.parse(json);
            sb.append(builder.build(response, o, ""));
        }
    } else
        sb.append(builder.build(response, response._response, ""));
    sb.append("</div></div></div>");
    return sb.toString();
}
Also used : AutoBuffer(water.AutoBuffer) RString(water.util.RString)

Aggregations

AutoBuffer (water.AutoBuffer)7 Test (org.junit.Test)4 RString (water.util.RString)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Ignore (org.junit.Ignore)1