use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class JobsResponse method render.
@Override
public void render(OutputStream stream) throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor jobArray = root.setArray("jobs");
for (String jobName : jobControl.jobs()) jobArray.addObject().setString("name", jobName);
Cursor inactiveArray = root.setArray("inactive");
for (String jobName : jobControl.inactiveJobs()) inactiveArray.addString(jobName);
new JsonFormat(true).encode(stream, slime);
}
use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class ResourcesResponse method render.
@Override
public void render(OutputStream stream) throws IOException {
String parentUrlString = parentUrl.toString();
if (!parentUrlString.endsWith("/"))
parentUrlString = parentUrlString + "/";
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor array = root.setArray("resources");
for (String subResource : subResources) {
array.addObject().setString("url", parentUrlString + subResource + "/");
}
new JsonFormat(true).encode(stream, slime);
}
use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class GenericConfigBuilderTest method getString.
private String getString(GenericConfig.GenericConfigBuilder builder) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
builder.getPayload().serialize(baos, new JsonFormat(true));
return baos.toString();
}
use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class ConfigUtils method getMd5.
/**
* Computes Md5 hash of a list of strings. The only change to input lines before
* computing md5 is to skip empty lines.
*
* @param payload a config payload
* @return the Md5 hash of the list, with lowercase letters
*/
public static String getMd5(ConfigPayload payload) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
payload.serialize(baos, new JsonFormat(true));
} catch (IOException e) {
throw new RuntimeException(e);
}
MessageDigest md5 = getMd5Instance();
md5.update(baos.toByteArray());
return HexDump.toHexString(md5.digest()).toLowerCase();
}
use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.
the class ConfigPayload method toUtf8Array.
public Utf8Array toUtf8Array(boolean compact) {
ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
try {
new JsonFormat(compact).encode(os, slime);
os.close();
} catch (IOException e) {
e.printStackTrace();
}
return new Utf8Array(os.toByteArray());
}
Aggregations