Package org.codehaus.jackson.util
Class JsonParserSequence
- java.lang.Object
-
- org.codehaus.jackson.JsonParser
-
- org.codehaus.jackson.util.JsonParserDelegate
-
- org.codehaus.jackson.util.JsonParserSequence
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Versioned
public class JsonParserSequence extends JsonParserDelegate
Helper class that can be used to sequence multiple physicalJsonParsers to create a single logical sequence of tokens, as a singleJsonParser.Fairly simple use of
JsonParserDelegate: only need to overridenextToken()to handle transition- Since:
- 1.5
- Author:
- tatu
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.codehaus.jackson.JsonParser
JsonParser.Feature, JsonParser.NumberType
-
-
Field Summary
Fields Modifier and Type Field Description protected int_nextParserIndex of the next parser in_parsers.protected JsonParser[]_parsersParsers other than the first one (which is initially assigned as delegate)-
Fields inherited from class org.codehaus.jackson.util.JsonParserDelegate
delegate
-
Fields inherited from class org.codehaus.jackson.JsonParser
_currToken, _features, _lastClearedToken
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJsonParserSequence(JsonParser[] parsers)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFlattenedActiveParsers(List<JsonParser> result)voidclose()Closes the parser so that no further iteration or data access can be made; will also close the underlying input source if parser either owns the input source, or featureJsonParser.Feature.AUTO_CLOSE_SOURCEis enabled.intcontainedParsersCount()Method that is most useful for debugging or testing; returns actual number of underlying parsers sequence was constructed with (nor just ones remaining active)static JsonParserSequencecreateFlattened(JsonParser first, JsonParser second)Method that will construct a parser (possibly a sequence) that contains all given sub-parsers.JsonTokennextToken()Main iteration method, which will advance stream enough to determine type of the next token, if any.protected booleanswitchToNext()Method that will switch active parser from the current one to next parser in sequence, if there is another parser left, making this the new delegate.-
Methods inherited from class org.codehaus.jackson.util.JsonParserDelegate
canUseSchema, clearCurrentToken, disable, enable, getBigIntegerValue, getBinaryValue, getBooleanValue, getByteValue, getCodec, getCurrentLocation, getCurrentName, getCurrentToken, getDecimalValue, getDoubleValue, getEmbeddedObject, getFloatValue, getInputSource, getIntValue, getLastClearedToken, getLongValue, getNumberType, getNumberValue, getParsingContext, getShortValue, getText, getTextCharacters, getTextLength, getTextOffset, getTokenLocation, hasCurrentToken, isClosed, isEnabled, setCodec, setSchema, skipChildren, version
-
Methods inherited from class org.codehaus.jackson.JsonParser
_constructError, configure, disableFeature, enableFeature, getBinaryValue, getValueAsBoolean, getValueAsBoolean, getValueAsDouble, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, hasTextCharacters, isExpectedStartArrayToken, isFeatureEnabled, nextBooleanValue, nextFieldName, nextIntValue, nextLongValue, nextTextValue, nextValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered, releaseBuffered, setFeature
-
-
-
-
Field Detail
-
_parsers
protected final JsonParser[] _parsers
Parsers other than the first one (which is initially assigned as delegate)
-
_nextParser
protected int _nextParser
Index of the next parser in_parsers.
-
-
Constructor Detail
-
JsonParserSequence
protected JsonParserSequence(JsonParser[] parsers)
-
-
Method Detail
-
createFlattened
public static JsonParserSequence createFlattened(JsonParser first, JsonParser second)
Method that will construct a parser (possibly a sequence) that contains all given sub-parsers. All parsers given are checked to see if they are sequences: and if so, they will be "flattened", that is, contained parsers are directly added in a new sequence instead of adding sequences within sequences. This is done to minimize delegation depth, ideally only having just a single level of delegation.
-
addFlattenedActiveParsers
protected void addFlattenedActiveParsers(List<JsonParser> result)
-
close
public void close() throws IOExceptionDescription copied from class:JsonParserCloses the parser so that no further iteration or data access can be made; will also close the underlying input source if parser either owns the input source, or featureJsonParser.Feature.AUTO_CLOSE_SOURCEis enabled. Whether parser owns the input source depends on factory method that was used to construct instance (so checkJsonFactoryfor details, but the general idea is that if caller passes in closable resource (such asInputStreamorReader) parser does NOT own the source; but if it passes a reference (such asFileorURLand creates stream or reader it does own them.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classJsonParserDelegate- Throws:
IOException
-
nextToken
public JsonToken nextToken() throws IOException, JsonParseException
Description copied from class:JsonParserMain iteration method, which will advance stream enough to determine type of the next token, if any. If none remaining (stream has no content other than possible white space before ending), null will be returned.- Overrides:
nextTokenin classJsonParserDelegate- Returns:
- Next token from the stream, if any found, or null to indicate end-of-input
- Throws:
IOExceptionJsonParseException
-
containedParsersCount
public int containedParsersCount()
Method that is most useful for debugging or testing; returns actual number of underlying parsers sequence was constructed with (nor just ones remaining active)
-
switchToNext
protected boolean switchToNext()
Method that will switch active parser from the current one to next parser in sequence, if there is another parser left, making this the new delegate. Old delegate is returned if switch succeeds.- Returns:
- True if switch succeeded; false otherwise
-
-