Interface JsonParser
- All Superinterfaces:
Handler<Buffer>, ReadStream<JsonEvent>, StreamBase
A parser class which allows to incrementally parse json elements and emit json parse events instead of parsing a json
element fully. This parser is convenient for parsing large json structures.
The parser also parses concatenated json streams or line delimited json streams.
The parser can also parse entire object or array when it is convenient, for instance a very large array
of small objects can be parsed efficiently by handling array start/end and object
events.
Whenever the parser fails to parse or process the stream, the
exceptionHandler(Handler) is called with
the cause of the failure and the current handling stops. After such event, the parser should not handle data
anymore.- Author:
- Julien Viet
-
Method Summary
Modifier and TypeMethodDescriptionFlip the parser to emit a stream of events for each new json array.Flip the parser to emit a single value event for each new json array.voidend()End the stream, this must be called after all the json stream has been processed.endHandler(Handler<Void> endHandler) Set an end handler.exceptionHandler(Handler<Throwable> handler) Set an exception handler on the read stream.fetch(long amount) Fetch the specifiedamountof elements.Set a data handler.static JsonParserCreate a newJsonParserinstance.static JsonParsernewParser(ReadStream<Buffer> stream) Create a newJsonParserinstance.Flip the parser to emit a stream of events for each new json object.Flip the parser to emit a single value event for each new json object.pause()Pause theReadStream, it sets the buffer infetchmode and clears the actual demand.resume()Resume reading, and sets the buffer inflowingmode.Handle aBuffer, pretty much like callingHandler.handle(Object).Methods inherited from interface ReadStream
blockingStream, collect, pipe, pipeTo
-
Method Details
-
newParser
Create a newJsonParserinstance. -
newParser
Create a newJsonParserinstance. -
write
Handle aBuffer, pretty much like callingHandler.handle(Object).- Returns:
- a reference to this, so the API can be used fluently
-
end
void end()End the stream, this must be called after all the json stream has been processed. -
objectEventMode
JsonParser objectEventMode()Flip the parser to emit a stream of events for each new json object.- Returns:
- a reference to this, so the API can be used fluently
-
objectValueMode
JsonParser objectValueMode()Flip the parser to emit a single value event for each new json object. Json object currently streamed won't be affected.- Returns:
- a reference to this, so the API can be used fluently
-
arrayEventMode
JsonParser arrayEventMode()Flip the parser to emit a stream of events for each new json array.- Returns:
- a reference to this, so the API can be used fluently
-
arrayValueMode
JsonParser arrayValueMode()Flip the parser to emit a single value event for each new json array. Json array currently streamed won't be affected.- Returns:
- a reference to this, so the API can be used fluently
-
pause
JsonParser pause()Description copied from interface:ReadStreamPause theReadStream, it sets the buffer infetchmode and clears the actual demand.While it's paused, no data will be sent to the data
handler.- Specified by:
pausein interfaceReadStream<JsonEvent>- Returns:
- a reference to this, so the API can be used fluently
-
resume
JsonParser resume()Description copied from interface:ReadStreamResume reading, and sets the buffer inflowingmode. If theReadStreamhas been paused, reading will recommence on it.- Specified by:
resumein interfaceReadStream<JsonEvent>- Returns:
- a reference to this, so the API can be used fluently
-
fetch
Description copied from interface:ReadStreamFetch the specifiedamountof elements. If theReadStreamhas been paused, reading will recommence with the specifiedamountof items, otherwise the specifiedamountwill be added to the current stream demand.- Specified by:
fetchin interfaceReadStream<JsonEvent>- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
Description copied from interface:ReadStreamSet an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.- Specified by:
endHandlerin interfaceReadStream<JsonEvent>- Returns:
- a reference to this, so the API can be used fluently
-
handler
Description copied from interface:ReadStreamSet a data handler. As data is read, the handler will be called with the data.- Specified by:
handlerin interfaceReadStream<JsonEvent>- Returns:
- a reference to this, so the API can be used fluently
-
exceptionHandler
Description copied from interface:ReadStreamSet an exception handler on the read stream.- Specified by:
exceptionHandlerin interfaceReadStream<JsonEvent>- Specified by:
exceptionHandlerin interfaceStreamBase- Parameters:
handler- the exception handler- Returns:
- a reference to this, so the API can be used fluently
-