public static Token seek(Parser parser, String[] path1) { return seek(parser, path1, null); }
/** * Seeks the field with the given name in the stream and positions (and returns) the parser to the next available token (value or not). * Return null if no token is found. * * @param path * @param parser * @return token associated with the given path or null if not found */ public static Token seek(Parser parser, String path) { // return current token if no path is given if (!StringUtils.hasText(path)) { return null; } List<String> tokens = StringUtils.tokenize(path, "."); return seek(parser, tokens.toArray(new String[tokens.size()])); }
@Test public void testNestedFieldSeek() throws Exception { Token seek = ParsingUtils.seek(nestedJsonParser, "nested.field"); assertNotNull(seek); }
@SuppressWarnings("rawtypes") Iterator<Map> parseBulkActionResponse(Response response) { InputStream content = response.body(); // Check for failed writes try { ObjectReader r = JsonFactory.objectReader(mapper, Map.class); JsonParser parser = mapper.getJsonFactory().createJsonParser(content); try { if (ParsingUtils.seek(new JacksonJsonParser(parser), "items") == null) { return Collections.<Map>emptyList().iterator(); } else { return r.readValues(parser); } } finally { countStreamStats(content); } } catch (IOException ex) { throw new EsHadoopParsingException(ex); } }
if (ParsingUtils.seek(new JacksonJsonParser(parser), "items") == null) { entries = Collections.<Map>emptyList().iterator(); } else {
@Test public void testNonExistingToken() throws Exception { assertNull(ParsingUtils.seek(parser, "nosuchtoken")); assertNull(parser.nextToken()); }
private long hitsTotal(Parser parser) { ParsingUtils.seek(parser, TOTAL);
@Test public void testOneLevelNestedField() throws Exception { assertNotNull(ParsingUtils.seek(parser, "address.state")); assertEquals(Token.VALUE_STRING, parser.currentToken()); assertEquals("state", parser.currentName()); }
@Test public void testFieldNestedButNotOnFirstLevel() throws Exception { assertNull(ParsingUtils.seek(parser, "state")); assertNull(parser.nextToken()); assertNull(parser.currentToken()); }
@Test public void testFieldName() throws Exception { assertNotNull(ParsingUtils.seek(parser, "age")); assertEquals(Token.VALUE_NUMBER, parser.currentToken()); assertEquals("age", parser.currentName()); }
public static Token seek(Parser parser, String[] path1) { return seek(parser, path1, null); }
public static Token seek(Parser parser, String[] path1) { return seek(parser, path1, null); }
public static Token seek(Parser parser, String[] path1) { return seek(parser, path1, null); }
public static Token seek(Parser parser, String[] path1) { return seek(parser, path1, null); }
private long hits() { ParsingUtils.seek(parser, TOTAL); long hits = parser.longValue(); return hits; }
/** * Seeks the field with the given name in the stream and positions (and returns) the parser to the next available token (value or not). * Return null if no token is found. * * @param path * @param parser * @return token associated with the given path or null if not found */ public static Token seek(Parser parser, String path) { // return current token if no path is given if (!StringUtils.hasText(path)) { return null; } List<String> tokens = StringUtils.tokenize(path, "."); return seek(parser, tokens.toArray(new String[tokens.size()])); }