List of usage examples for org.apache.lucene.util CharsRefBuilder copyUTF8Bytes
public void copyUTF8Bytes(byte[] bytes, int offset, int length)
From source file:org.elasticsearch.action.search.TransportSearchHelper.java
License:Apache License
static ParsedScrollId parseScrollId(String scrollId) { CharsRefBuilder spare = new CharsRefBuilder(); try {/*from w w w. j a v a 2 s . c o m*/ byte[] decode = Base64.decode(scrollId, Base64.URL_SAFE); spare.copyUTF8Bytes(decode, 0, decode.length); } catch (Exception e) { throw new IllegalArgumentException("Failed to decode scrollId", e); } String[] elements = Strings.splitStringToArray(spare.get(), ';'); if (elements.length < 2) { throw new IllegalArgumentException("Malformed scrollId [" + scrollId + "]"); } int index = 0; String type = elements[index++]; int contextSize = Integer.parseInt(elements[index++]); if (elements.length < contextSize + 2) { throw new IllegalArgumentException("Malformed scrollId [" + scrollId + "]"); } ScrollIdForNode[] context = new ScrollIdForNode[contextSize]; for (int i = 0; i < contextSize; i++) { String element = elements[index++]; int sep = element.indexOf(':'); if (sep == -1) { throw new IllegalArgumentException("Malformed scrollId [" + scrollId + "]"); } context[i] = new ScrollIdForNode(element.substring(sep + 1), Long.parseLong(element.substring(0, sep))); } Map<String, String> attributes; int attributesSize = Integer.parseInt(elements[index++]); if (attributesSize == 0) { attributes = ImmutableMap.of(); } else { attributes = Maps.newHashMapWithExpectedSize(attributesSize); for (int i = 0; i < attributesSize; i++) { String element = elements[index++]; int sep = element.indexOf(':'); attributes.put(element.substring(0, sep), element.substring(sep + 1)); } } return new ParsedScrollId(scrollId, type, context, attributes); }
From source file:org.elasticsearch.common.bytes.PagedBytesReference.java
License:Apache License
@Override public String toUtf8() { if (length() == 0) { return ""; }//from w w w.ja v a2s. c o m byte[] bytes = toBytes(); final CharsRefBuilder ref = new CharsRefBuilder(); ref.copyUTF8Bytes(bytes, offset, length); return ref.toString(); }