use of org.noggit.CharArr in project lucene-solr by apache.
the class SmileWriterTest method testTypes.
@Test
public void testTypes() throws IOException {
SolrQueryRequest req = req("dummy");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("data1", Float.NaN);
rsp.add("data2", Double.NEGATIVE_INFINITY);
rsp.add("data3", Float.POSITIVE_INFINITY);
SmileResponseWriter smileResponseWriter = new SmileResponseWriter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
smileResponseWriter.write(baos, req, rsp);
Map m = (Map) decodeSmile(new ByteArrayInputStream(baos.toByteArray()));
CharArr out = new CharArr();
JSONWriter jsonWriter = new JSONWriter(out, 2);
// indentation by default
jsonWriter.setIndentSize(-1);
jsonWriter.write(m);
String s = new String(Utils.toUTF8(out), StandardCharsets.UTF_8);
assertEquals(s, "{\"data1\":NaN,\"data2\":-Infinity,\"data3\":Infinity}");
req.close();
}
use of org.noggit.CharArr in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method printClusterStateInfo.
protected String printClusterStateInfo(String collection) throws Exception {
cloudClient.getZkStateReader().forceUpdateCollection(collection);
String cs = null;
ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
if (collection != null) {
cs = clusterState.getCollection(collection).toString();
} else {
Map<String, DocCollection> map = clusterState.getCollectionsMap();
CharArr out = new CharArr();
new JSONWriter(out, 2).write(map);
cs = out.toString();
}
return cs;
}
use of org.noggit.CharArr in project lucene-solr by apache.
the class SolrTestCaseJ4 method jsonDelId.
/** Creates a JSON delete command from an id list */
public static String jsonDelId(Object... ids) {
CharArr out = new CharArr();
try {
out.append('{');
boolean first = true;
for (Object id : ids) {
if (first)
first = false;
else
out.append(',');
out.append("\"delete\":{\"id\":");
out.append(JSONUtil.toJSON(id));
out.append('}');
}
out.append('}');
} catch (IOException e) {
// should never happen
}
return out.toString();
}
use of org.noggit.CharArr in project lucene-solr by apache.
the class SolrTestCaseJ4 method toJSON.
public static String toJSON(Doc doc) {
CharArr out = new CharArr();
try {
out.append("{\"add\":{\"doc\":{");
boolean firstField = true;
for (Fld fld : doc.fields) {
if (firstField)
firstField = false;
else
out.append(',');
JSONUtil.writeString(fld.ftype.fname, 0, fld.ftype.fname.length(), out);
out.append(':');
if (fld.vals.size() > 1) {
out.append('[');
}
boolean firstVal = true;
for (Comparable val : fld.vals) {
if (firstVal)
firstVal = false;
else
out.append(',');
out.append(JSONUtil.toJSON(val));
}
if (fld.vals.size() > 1) {
out.append(']');
}
}
out.append("}}}");
} catch (IOException e) {
// should never happen
}
return out.toString();
}
use of org.noggit.CharArr in project lucene-solr by apache.
the class SolrTestCaseJ4 method json.
/** Creates JSON from a SolrInputDocument. Doesn't currently handle boosts.
* @see #json(SolrInputDocument,CharArr)
*/
public static String json(SolrInputDocument doc) {
CharArr out = new CharArr();
json(doc, out);
return out.toString();
}
Aggregations