Search in sources :

Example 1 with CharArr

use of org.noggit.CharArr in project disgear by yangbutao.

the class ZkStateReader method fromJSON.

public static Object fromJSON(byte[] utf8) {
    // convert directly from bytes to chars
    // and parse directly from that instead of going through
    // intermediate strings or readers
    CharArr chars = new CharArr();
    ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars);
    JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length());
    try {
        return ObjectBuilder.getVal(parser);
    } catch (IOException e) {
        // should never happen w/o using real
        throw new RuntimeException(e);
    // IO
    }
}
Also used : JSONParser(org.noggit.JSONParser) IOException(java.io.IOException) CharArr(org.noggit.CharArr)

Example 2 with CharArr

use of org.noggit.CharArr in project disgear by yangbutao.

the class ZkStateReader method toJSON.

public static byte[] toJSON(Object o) {
    CharArr out = new CharArr();
    // indentation by default
    new JSONWriter(out, 2).write(o);
    return toUTF8(out);
}
Also used : JSONWriter(org.noggit.JSONWriter) CharArr(org.noggit.CharArr)

Example 3 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class Utils method fromJSON.

public static Object fromJSON(byte[] utf8) {
    // convert directly from bytes to chars
    // and parse directly from that instead of going through
    // intermediate strings or readers
    CharArr chars = new CharArr();
    ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars);
    JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length());
    try {
        return ObjectBuilder.getVal(parser);
    } catch (IOException e) {
        // should never happen w/o using real IO
        throw new RuntimeException(e);
    }
}
Also used : JSONParser(org.noggit.JSONParser) IOException(java.io.IOException) CharArr(org.noggit.CharArr)

Example 4 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class Utils method toJSON.

public static byte[] toJSON(Object o) {
    if (o == null)
        return new byte[0];
    CharArr out = new CharArr();
    // indentation by default
    new JSONWriter(out, 2).write(o);
    return toUTF8(out);
}
Also used : JSONWriter(org.noggit.JSONWriter) CharArr(org.noggit.CharArr)

Example 5 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class TestDelegationTokenResponse method getNestedMapJson.

private String getNestedMapJson(String outerKey, String innerKey, Object innerValue) {
    CharArr out = new CharArr();
    JSONWriter w = new JSONWriter(out, 2);
    Map<String, Object> innerMap = new HashMap<String, Object>();
    innerMap.put(innerKey, innerValue);
    Map<String, Map<String, Object>> outerMap = new HashMap<String, Map<String, Object>>();
    outerMap.put(outerKey, innerMap);
    w.write(outerMap);
    return out.toString();
}
Also used : JSONWriter(org.noggit.JSONWriter) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) CharArr(org.noggit.CharArr)

Aggregations

CharArr (org.noggit.CharArr)14 IOException (java.io.IOException)6 JSONWriter (org.noggit.JSONWriter)6 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONParser (org.noggit.JSONParser)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 ClusterState (org.apache.solr.common.cloud.ClusterState)1 DocCollection (org.apache.solr.common.cloud.DocCollection)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 RTimer (org.apache.solr.util.RTimer)1 Test (org.junit.Test)1