Java Code Examples for org.noggit.JSONParser#ARRAY_END

The following examples show how to use org.noggit.JSONParser#ARRAY_END . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONTupleStream.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** returns the next Tuple or null */
@Override
@SuppressWarnings({"unchecked"})
public Map<String,Object> next() throws IOException {
  if (!atDocs) {
    boolean found = advanceToDocs();
    atDocs = true;
    if (!found) return null;
  }
  // advance past ARRAY_START (in the case that we just advanced to docs, or OBJECT_END left over from the last call.
  int event = parser.nextEvent();
  if (event == JSONParser.ARRAY_END) return null;

  Object o = ObjectBuilder.getVal(parser);
  // right now, getVal will leave the last event read as OBJECT_END

  return (Map<String,Object>)o;
}
 
Example 2
Source File: JSONTupleStream.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void skipArray(String key, boolean deepSearch) throws IOException {
  for (;;) {
    int event = parser.nextEvent();
    switch (event) {
      case JSONParser.OBJECT_START:
        advanceToMapKey(key, deepSearch);
        break;
      case JSONParser.ARRAY_START:
        skipArray(key, deepSearch);
        break;
      case JSONParser.ARRAY_END:
        return;
    }
  }
}
 
Example 3
Source File: JSONUtil.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static void skipArray(JSONParser parser, String key, boolean deepSearch) throws IOException {
  for (;;) {
    int event = parser.nextEvent();
    switch (event) {
      case JSONParser.OBJECT_START:
        advanceToMapKey(parser, key, deepSearch);
        break;
      case JSONParser.ARRAY_START:
        skipArray(parser, key, deepSearch);
        break;
      case JSONParser.ARRAY_END:
        return;
    }
  }
}
 
Example 4
Source File: JsonLoader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
void handleAdds() throws IOException {
  while (true) {
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    cmd.commitWithin = commitWithin;
    cmd.overwrite = overwrite;

    int ev = parser.nextEvent();
    if (ev == JSONParser.ARRAY_END) break;

    assertEvent(ev, JSONParser.OBJECT_START);
    cmd.solrDoc = parseDoc(ev);
    processor.processAdd(cmd);
  }
}
 
Example 5
Source File: MtasSolrComponentCollection.java    From mtas with Apache License 2.0 5 votes vote down vote up
/**
 * String to string values.
 *
 * @param stringValue the string value
 * @return the hash set
 * @throws IOException Signals that an I/O exception has occurred.
 */
private static HashSet<String> stringToStringValues(String stringValue)
    throws IOException {
  // should be improved to support escaped characters
  HashSet<String> stringValues = new HashSet<>();
  JSONParser jsonParser = new JSONParser(stringValue);
  int event = jsonParser.nextEvent();
  if (event == JSONParser.ARRAY_START) {
    while ((event = jsonParser.nextEvent()) != JSONParser.ARRAY_END) {
      if (jsonParser.getLevel() == 1) {
        switch (event) {
        case JSONParser.STRING:
          stringValues.add(jsonParser.getString());
          break;
        case JSONParser.BIGNUMBER:
        case JSONParser.NUMBER:
        case JSONParser.LONG:
          stringValues.add(jsonParser.getNumberChars().toString());
          break;
        case JSONParser.BOOLEAN:
          stringValues.add(Boolean.toString(jsonParser.getBoolean()));
          break;
        default:
          // do nothing
          break;
        }
      }
    }
  } else {
    throw new IOException("unsupported json structure");
  }
  return stringValues;
}