use of org.json.simple.JsonArray in project eiger by wlloyd.
the class SSTableExportTest method testEscapingDoubleQuotes.
@Test
public void testEscapingDoubleQuotes() throws IOException {
File tempSS = tempSSTableFile("Keyspace1", "ValuesWithQuotes");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "ValuesWithQuotes");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(null, new Column(ByteBufferUtil.bytes("data"), UTF8Type.instance.fromString("{\"foo\":\"bar\"}")));
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("ValuesWithQuotes", ".json");
SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
JSONArray data = (JSONArray) rowA.get(0);
assert hexToBytes((String) data.get(0)).equals(ByteBufferUtil.bytes("data"));
assert data.get(1).equals("{\"foo\":\"bar\"}");
}
use of org.json.simple.JsonArray in project eiger by wlloyd.
the class SSTableExportTest method testExportCounterCf.
@Test
public void testExportCounterCf() throws IOException {
File tempSS = tempSSTableFile("Keyspace1", "Counter1");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Counter1");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(null, new CounterColumn(ByteBufferUtil.bytes("colA"), 42, System.currentTimeMillis()));
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("Counter1", ".json");
SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
JSONArray colA = (JSONArray) rowA.get(0);
assert hexToBytes((String) colA.get(0)).equals(ByteBufferUtil.bytes("colA"));
assert ((String) colA.get(3)).equals("c");
assert (Long) colA.get(4) == Long.MIN_VALUE;
}
use of org.json.simple.JsonArray in project Glowstone by GlowstoneMC.
the class JsonListFile method save.
/**
* Saves to the file.
*/
@SuppressWarnings("unchecked")
protected void save() {
JSONArray array = new JSONArray();
for (BaseEntry entry : entries) {
JSONObject obj = new JSONObject();
for (Entry<String, String> mapEntry : entry.write().entrySet()) {
obj.put(mapEntry.getKey(), mapEntry.getValue());
}
array.add(obj);
}
try (Writer writer = new FileWriter(file)) {
array.writeJSONString(writer);
} catch (Exception ex) {
GlowServer.logger.log(Level.SEVERE, "Error writing to: " + file, ex);
}
}
use of org.json.simple.JsonArray in project Glowstone by GlowstoneMC.
the class Metrics method getPluginData.
/**
* Gets the plugin specific data.
* This method is called using Reflection.
*
* @return The plugin specific data.
*/
public JSONObject getPluginData() {
JSONObject data = new JSONObject();
String pluginName = server.getName();
String pluginVersion = server.getVersion();
// Append the name of the plugin
data.put("pluginName", pluginName);
// Append the version of the plugin
data.put("pluginVersion", pluginVersion);
JSONArray customCharts = new JSONArray();
for (CustomChart customChart : charts) {
// Add the data of the custom charts
JSONObject chart = customChart.getRequestJsonObject();
if (chart == null) {
// If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.put("customCharts", customCharts);
return data;
}
use of org.json.simple.JsonArray in project Glowstone by GlowstoneMC.
the class PlayerDataFetcher method getUUID.
/**
* Look up the UUID for a given username.
*
* @param playerName The name to look up.
* @return The UUID, or null on failure.
*/
public static UUID getUUID(String playerName) {
HttpsURLConnection conn;
try {
URL url = new URL(UUID_URL);
conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
} catch (IOException e) {
GlowServer.logger.log(Level.WARNING, "Failed to look up UUID", e);
return null;
}
List<String> playerList = new ArrayList<>();
playerList.add(playerName);
JSONArray json;
try {
try (DataOutputStream os = new DataOutputStream(conn.getOutputStream())) {
os.writeBytes(JSONValue.toJSONString(playerList));
}
json = (JSONArray) JSONValue.parse(new InputStreamReader(conn.getInputStream()));
} catch (IOException e) {
GlowServer.logger.warning("Couldn't get UUID due to IO error: " + e);
return null;
}
if (!json.isEmpty()) {
String uuid = (String) ((JSONObject) json.get(0)).get("id");
return UuidUtils.fromFlatString(uuid);
}
return null;
}
Aggregations