Search in sources :

Example 76 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project hadoop by apache.

the class DomainLogInfo method parsePath.

private long parsePath(TimelineDataManager tdm, Path logPath, boolean appCompleted, JsonFactory jsonFactory, ObjectMapper objMapper, FileSystem fs) throws IOException {
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(user);
    FSDataInputStream in = fs.open(logPath);
    JsonParser parser = null;
    try {
        in.seek(offset);
        try {
            parser = jsonFactory.createParser(in);
            parser.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
        } catch (IOException e) {
            // incomplete file which are treated as EOF until app completes
            if (appCompleted) {
                throw e;
            } else {
                LOG.debug("Exception in parse path: {}", e.getMessage());
                return 0;
            }
        }
        return doParse(tdm, parser, objMapper, ugi, appCompleted);
    } finally {
        IOUtils.closeStream(parser);
        IOUtils.closeStream(in);
    }
}
Also used : FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 77 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method parse.

/**
   * Reads an {@link Reader} and parses its contents into a list of Data objects.
   *
   * @param in provides the {@link Reader}
   * @param mesg provides the {@link StringBuilder} to store validation error messages,
   *             such as duplicate keys in the same {@link DataMap}.
   * @param locationMap provides where to store the mapping of a Data object
   *                    to its location in the in the {@link Reader}. may be
   *                    {@code null} if this mapping is not needed by the caller.
   *                    This map should usually be an {@link IdentityHashMap}.
   * @return the list of Data objects parsed from the {@link Reader}.
   * @throws IOException if there is a syntax error in the input.
   */
public List<Object> parse(Reader in, StringBuilder mesg, Map<Object, DataLocation> locationMap) throws IOException {
    final Parser parser = new Parser(true);
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(in);
        return parser.parse(jsonParser, mesg, locationMap);
    } catch (IOException e) {
        throw e;
    } finally {
        closeJsonParserQuietly(jsonParser);
    }
}
Also used : IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 78 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method readList.

@Override
public DataList readList(InputStream in) throws IOException {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(in);
        return parser.parse(jsonParser, DataList.class);
    } catch (IOException e) {
        throw e;
    } finally {
        closeJsonParserQuietly(jsonParser);
    }
}
Also used : IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 79 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method readMap.

@Override
public DataMap readMap(Reader in) throws IOException {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(in);
        return parser.parse(jsonParser, DataMap.class);
    } catch (IOException e) {
        throw e;
    } finally {
        closeJsonParserQuietly(jsonParser);
    }
}
Also used : IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 80 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method readList.

@Override
public DataList readList(Reader in) throws IOException {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(in);
        return parser.parse(jsonParser, DataList.class);
    } catch (IOException e) {
        throw e;
    } finally {
        closeJsonParserQuietly(jsonParser);
    }
}
Also used : IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)144 IOException (java.io.IOException)43 Test (org.junit.Test)35 JsonFactory (com.fasterxml.jackson.core.JsonFactory)26 StringWriter (java.io.StringWriter)17 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)15 JsonToken (com.fasterxml.jackson.core.JsonToken)14 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)12 SqlNullable (com.facebook.presto.spi.function.SqlNullable)11 SqlType (com.facebook.presto.spi.function.SqlType)11 BaseTest (com.fasterxml.jackson.core.BaseTest)11 UTF8DataInputJsonParser (com.fasterxml.jackson.core.json.UTF8DataInputJsonParser)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 JsonParseException (com.fasterxml.jackson.core.JsonParseException)9 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)7 PrestoException (com.facebook.presto.spi.PrestoException)6 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)5