Search in sources :

Example 1 with JsonWriter

use of dontweave.gson.stream.JsonWriter in project h2o-2 by h2oai.

the class WebAPI method exportModel.

/**
   * Exports a model to a JSON file.
   */
static void exportModel() throws Exception {
    HttpClient client = new HttpClient();
    GetMethod get = new GetMethod(URL + "/2/ExportModel.json?model=MyInitialNeuralNet");
    int status = client.executeMethod(get);
    if (status != 200)
        throw new Exception(get.getStatusText());
    JsonObject response = (JsonObject) new JsonParser().parse(new InputStreamReader(get.getResponseBodyAsStream()));
    JsonElement model = response.get("model");
    JsonWriter writer = new JsonWriter(new FileWriter(JSON_FILE));
    writer.setLenient(true);
    writer.setIndent("  ");
    Streams.write(model, writer);
    writer.close();
    get.releaseConnection();
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonElement(dontweave.gson.JsonElement) HttpClient(org.apache.commons.httpclient.HttpClient) FileWriter(java.io.FileWriter) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonObject(dontweave.gson.JsonObject) JsonWriter(dontweave.gson.stream.JsonWriter) JsonParser(dontweave.gson.JsonParser)

Aggregations

JsonElement (dontweave.gson.JsonElement)1 JsonObject (dontweave.gson.JsonObject)1 JsonParser (dontweave.gson.JsonParser)1 JsonWriter (dontweave.gson.stream.JsonWriter)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1