Ejemplo n.º 1
0
 @Override
 public String toString() {
   return "["
       + Arrays.toString(indices)
       + "]["
       + Arrays.toString(types)
       + "], querySource["
       + Unicode.fromBytes(querySource)
       + "]";
 }
 public static ParsedScrollId parseScrollId(String scrollId) {
   try {
     scrollId = Unicode.fromBytes(Base64.decode(scrollId, Base64.URL_SAFE));
   } catch (IOException e) {
     throw new ElasticSearchIllegalArgumentException("Failed to decode scrollId", e);
   }
   String[] elements = Strings.splitStringToArray(scrollId, ';');
   int index = 0;
   String type = elements[index++];
   int contextSize = Integer.parseInt(elements[index++]);
   @SuppressWarnings({"unchecked"})
   Tuple<String, Long>[] context = new Tuple[contextSize];
   for (int i = 0; i < contextSize; i++) {
     String element = elements[index++];
     int sep = element.indexOf(':');
     if (sep == -1) {
       throw new ElasticSearchIllegalArgumentException("Malformed scrollId [" + scrollId + "]");
     }
     context[i] =
         new Tuple<String, Long>(
             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);
 }