Search in sources :

Example 71 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getJsonObj.

public JsonObject getJsonObj(String string, MultivaluedMap<String, String> queryParams, long duration) {
    if (string.equals("")) {
        return null;
    }
    String key = getCacheKey(string, queryParams, duration);
    JsonObject res = getJsonObjectFromCache(key, duration);
    if (res != null) {
        return res;
    }
    JsonReader reader = getReader(string, queryParams);
    res = reader.readObject();
    reader.close();
    if (duration > 0) {
        cache.put(key, new CacheEntry(res));
    }
    return res;
}
Also used : JsonObject(javax.json.JsonObject) JsonReader(javax.json.JsonReader) JsonString(javax.json.JsonString)

Example 72 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getMapStringSnapshotTabularDataValue.

public Map<String, TabularData> getMapStringSnapshotTabularDataValue(String string, MultivaluedMap<String, String> queryParams) {
    if (string.equals("")) {
        return null;
    }
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    Map<String, TabularData> map = new HashMap<>();
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.getJsonObject(i);
        if (obj.containsKey("key") && obj.containsKey("value")) {
            String key = obj.getString("key");
            map.put(key, getSnapshotData(key, obj.getJsonArray("value")));
        }
    }
    reader.close();
    return map;
}
Also used : JsonArray(javax.json.JsonArray) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) TabularData(javax.management.openmbean.TabularData) SnapshotDetailsTabularData(com.scylladb.jmx.utils.SnapshotDetailsTabularData)

Example 73 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getIntArrValue.

public int[] getIntArrValue(String string, MultivaluedMap<String, String> queryParams) {
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    int[] res = new int[arr.size()];
    for (int i = 0; i < arr.size(); i++) {
        res[i] = arr.getInt(i);
    }
    reader.close();
    return res;
}
Also used : JsonArray(javax.json.JsonArray) JsonReader(javax.json.JsonReader)

Example 74 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getMapStringDouble.

public Map<String, Double> getMapStringDouble(String string, MultivaluedMap<String, String> queryParams) {
    if (string.equals("")) {
        return null;
    }
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    Map<String, Double> map = new HashMap<String, Double>();
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.getJsonObject(i);
        Iterator<String> it = obj.keySet().iterator();
        String key = "";
        double val = -1;
        while (it.hasNext()) {
            String k = it.next();
            if (obj.get(k) instanceof JsonString) {
                key = obj.getString(k);
            } else {
                val = obj.getJsonNumber(k).doubleValue();
            }
        }
        if (!key.equals("")) {
            map.put(key, val);
        }
    }
    reader.close();
    return map;
}
Also used : JsonArray(javax.json.JsonArray) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString)

Example 75 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getMapInetAddressFloatValue.

public Map<InetAddress, Float> getMapInetAddressFloatValue(String string, MultivaluedMap<String, String> queryParams) {
    Map<InetAddress, Float> res = new HashMap<InetAddress, Float>();
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    JsonObject obj = null;
    for (int i = 0; i < arr.size(); i++) {
        try {
            obj = arr.getJsonObject(i);
            res.put(InetAddress.getByName(obj.getString("key")), Float.parseFloat(obj.getString("value")));
        } catch (UnknownHostException e) {
            logger.warning("Bad formatted address " + obj.getString("key"));
        }
    }
    return res;
}
Also used : JsonArray(javax.json.JsonArray) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) InetAddress(java.net.InetAddress)

Aggregations

JsonReader (javax.json.JsonReader)130 JsonObject (javax.json.JsonObject)110 StringReader (java.io.StringReader)78 Test (org.junit.Test)47 JsonArray (javax.json.JsonArray)44 JsonString (javax.json.JsonString)42 HashMap (java.util.HashMap)21 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)13 File (java.io.File)10 LinkedHashMap (java.util.LinkedHashMap)10 JsonParser (edu.harvard.iq.dataverse.util.json.JsonParser)9 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)8 InputStream (java.io.InputStream)7 Gson (com.google.gson.Gson)6 AsyncCompletionHandler (com.ning.http.client.AsyncCompletionHandler)6 Response (com.ning.http.client.Response)6 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)5