@Override public CharArr subSequence(int start, int end) { return new CharArr(buf, this.start+start, this.start+end); }
@Override public CharArr subSequence(int start, int end) { return new CharArr(buf, this.start+start, this.start+end); }
/** 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(); }
public static String toJSON(Object o) { CharArr out = new CharArr(); new JSONWriter(out).write(o); return out.toString(); }
public static byte[] toJSON(Object o) { if(o == null) return new byte[0]; CharArr out = new CharArr(); if (!(o instanceof List) && !(o instanceof Map)) { if (o instanceof MapWriter) { o = ((MapWriter)o).toMap(new LinkedHashMap<>()); } else if(o instanceof IteratorWriter){ o = ((IteratorWriter)o).toList(new ArrayList<>()); } } new MapWriterJSONWriter(out, 2).write(o); // indentation by default return toUTF8(out); }
/** * @param o The object to convert to JSON * @param indentSize The number of space characters to use as an indent (default 2). 0=newlines but no spaces, -1=no indent at all. * @return */ public static String toJSON(Object o, int indentSize) { CharArr out = new CharArr(); new JSONWriter(out,indentSize).write(o); return out.toString(); }
public static byte[] toJSON(Object o) { CharArr out = new CharArr(); new JSONWriter(out, 2).write(o); // indentation by default return toUTF8(out); }
/** * @param o The object to convert to JSON * @param indentSize The number of space characters to use as an indent (default 2). 0=newlines but no spaces, -1=no indent at all. * @return */ public static String toJSON(Object o, int indentSize) { CharArr out = new CharArr(); new JSONWriter(out,indentSize).write(o); return out.toString(); }
public static byte[] toJSON(Object o) { CharArr out = new CharArr(); new JSONWriter(out, 2).write(o); // indentation by default return toUTF8(out); }
public static String toJSON(Object o) { CharArr out = new CharArr(); new JSONWriter(out).write(o); return out.toString(); }
public String get(StringBytes b) { String result = cache.get(b); if (result == null) { //make a copy because the buffer received may be changed later by the caller StringBytes copy = new StringBytes(Arrays.copyOfRange(b.bytes, b.offset, b.offset + b.length), 0, b.length); CharArr arr = new CharArr(); ByteUtils.UTF8toUTF16(b.bytes, b.offset, b.length, arr); result = arr.toString(); cache.put(copy, result); } return result; } }
@Override public Collection<ContentStream> getContentStreams() throws IOException { CharArr json = new CharArr(); new SchemaRequestJSONWriter(json).write(getRequestParameters()); return Collections.<ContentStream>singletonList(new ContentStreamBase.StringStream(json.toString())); }
public String get(StringBytes b) { String result = cache.get(b); if (result == null) { //make a copy because the buffer received may be changed later by the caller StringBytes copy = new StringBytes(Arrays.copyOfRange(b.bytes, b.offset, b.offset + b.length), 0, b.length); CharArr arr = new CharArr(); ByteUtils.UTF8toUTF16(b.bytes, b.offset, b.length, arr); result = arr.toString(); cache.put(copy, result); } return result; } }
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) { throw new RuntimeException(e); // should never happen w/o using real IO } }
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) { throw new RuntimeException(e); // should never happen w/o using real // IO } }
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()); parser.setFlags(parser.getFlags() | JSONParser.ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT | JSONParser.OPTIONAL_OUTER_BRACES); try { return STANDARDOBJBUILDER.apply(parser).getVal(parser); } catch (IOException e) { throw new RuntimeException(e); // should never happen w/o using real IO } }
/** Creates a JSON add command from a SolrInputDocument list. Doesn't currently handle boosts. */ public static String jsonAdd(SolrInputDocument... docs) { CharArr out = new CharArr(); try { out.append('['); boolean firstField = true; for (SolrInputDocument doc : docs) { if (firstField) firstField=false; else out.append(','); out.append(json(doc)); } out.append(']'); } catch (IOException e) { // should never happen } return out.toString(); }
/** 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(); }
/** Creates a JSON deleteByQuery command */ public static String jsonDelQ(String... queries) { CharArr out = new CharArr(); try { out.append('{'); boolean first = true; for (Object q : queries) { if (first) first=false; else out.append(','); out.append("\"delete\":{\"query\":"); out.append(JSONUtil.toJSON(q)); out.append('}'); } out.append('}'); } catch (IOException e) { // should never happen } return out.toString(); }
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; }