Example usage for com.fasterxml.jackson.databind MappingIterator getParser

List of usage examples for com.fasterxml.jackson.databind MappingIterator getParser

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind MappingIterator getParser.

Prototype

public JsonParser getParser() 

Source Link

Document

Accessor for getting underlying parser this iterator uses.

Usage

From source file:com.github.fge.jackson.JsonNodeReader.java

private static JsonNode readNode(final MappingIterator<JsonNode> iterator) throws IOException {
    final Object source = iterator.getParser().getInputSource();
    final JsonParseExceptionBuilder builder = new JsonParseExceptionBuilder(source);

    builder.setMessage(BUNDLE.getMessage("read.noContent"));

    if (!iterator.hasNextValue())
        throw builder.build();

    final JsonNode ret = iterator.nextValue();

    builder.setMessage(BUNDLE.getMessage("read.trailingData")).setLocation(iterator.getCurrentLocation());

    try {/*from  www .  j av a2s.  c om*/
        if (iterator.hasNextValue())
            throw builder.build();
    } catch (JsonParseException e) {
        throw builder.setLocation(e.getLocation()).build();
    }

    return ret;
}

From source file:org.wikidata.wdtk.dumpfiles.JsonDumpFileProcessor.java

/**
 * Process dump file data from the given input stream. This method uses the
 * efficient Jackson {@link MappingIterator}. However, this class cannot
 * recover from processing errors. If an error occurs in one entity, the
 * (presumably) less efficient processing method
 * {@link #processDumpFileContentsRecovery(InputStream)} is used instead.
 *
 * @see MwDumpFileProcessor#processDumpFileContents(InputStream, MwDumpFile)
 *//*w  w  w . j  a  v a 2  s .  co  m*/
@Override
public void processDumpFileContents(InputStream inputStream, MwDumpFile dumpFile) {

    logger.info("Processing JSON dump file " + dumpFile.toString());

    try {
        try {
            MappingIterator<JacksonTermedStatementDocument> documentIterator = documentReader
                    .readValues(inputStream);
            documentIterator.getParser().disable(Feature.AUTO_CLOSE_SOURCE);

            while (documentIterator.hasNextValue()) {
                JacksonTermedStatementDocument document = documentIterator.nextValue();
                handleDocument(document);
            }
            documentIterator.close();
        } catch (JsonProcessingException e) {
            logJsonProcessingException(e);
            processDumpFileContentsRecovery(inputStream);
        }
    } catch (IOException e) {
        throw new RuntimeException("Cannot read JSON input: " + e.getMessage(), e);
    }

}