Class: Vertx::JsonParser
- Inherits:
-
Object
- Object
- Vertx::JsonParser
- Includes:
- ReadStream
- Defined in:
- /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb
Overview
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 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 #exception_handler is called with
the cause of the failure and the current handling stops. After such event, the parser should not handle data
anymore.
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary (collapse)
- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
-
+ (::Vertx::JsonParser) new_parser(stream = nil)
Create a new JsonParser instance.
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (self) array_event_mode
Flip the parser to emit a stream of events for each new json array.
-
- (self) array_value_mode
Flip the parser to emit a single value event for each new json array.
-
- (void) end
End the stream, this must be called after all the json stream has been processed.
- - (self) end_handler { ... }
- - (self) exception_handler { ... }
-
- (void) handle(event = nil)
Something has happened, so handle it.
- - (self) handler { ... }
-
- (self) object_event_mode
Flip the parser to emit a stream of events for each new json object.
-
- (self) object_value_mode
Flip the parser to emit a single value event for each new json object.
- - (self) pause
- - (self) resume
-
- (self) write(buffer = nil)
Handle a Buffer, pretty much like calling Proc#handle.
Class Method Details
+ (Boolean) accept?(obj)
30 31 32 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 30 def @@j_api_type.accept?(obj) obj.class == JsonParser end |
+ (Object) j_api_type
39 40 41 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 39 def self.j_api_type @@j_api_type end |
+ (Object) j_class
42 43 44 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 42 def self.j_class Java::IoVertxCoreParsetools::JsonParser.java_class end |
+ (::Vertx::JsonParser) new_parser(stream = nil)
Create a new
JsonParser instance.
57 58 59 60 61 62 63 64 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 57 def self.new_parser(stream=nil) if !block_given? && stream == nil return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::JsonParser.java_method(:newParser, []).call(),::Vertx::JsonParser) elsif stream.class.method_defined?(:j_del) && !block_given? return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::JsonParser.java_method(:newParser, [Java::IoVertxCoreStreams::ReadStream.java_class]).call(stream.j_del),::Vertx::JsonParser) end raise ArgumentError, "Invalid arguments when calling new_parser(#{stream})" end |
+ (Object) unwrap(obj)
36 37 38 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 36 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
33 34 35 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 33 def @@j_api_type.wrap(obj) JsonParser.new(obj) end |
Instance Method Details
- (self) array_event_mode
Flip the parser to emit a stream of events for each new json array.
105 106 107 108 109 110 111 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 105 def array_event_mode if !block_given? @j_del.java_method(:arrayEventMode, []).call() return self end raise ArgumentError, "Invalid arguments when calling array_event_mode()" end |
- (self) array_value_mode
Flip the parser to emit a single value event for each new json array.
Json array currently streamed won't be affected.
116 117 118 119 120 121 122 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 116 def array_value_mode if !block_given? @j_del.java_method(:arrayValueMode, []).call() return self end raise ArgumentError, "Invalid arguments when calling array_value_mode()" end |
- (void) end
This method returns an undefined value.
End the stream, this must be called after all the json stream has been processed.
77 78 79 80 81 82 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 77 def end if !block_given? return @j_del.java_method(:end, []).call() end raise ArgumentError, "Invalid arguments when calling end()" end |
- (self) end_handler { ... }
141 142 143 144 145 146 147 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 141 def end_handler if block_given? @j_del.java_method(:endHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield }) return self end raise ArgumentError, "Invalid arguments when calling end_handler()" end |
- (self) exception_handler { ... }
159 160 161 162 163 164 165 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 159 def exception_handler if block_given? @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) })) return self end raise ArgumentError, "Invalid arguments when calling exception_handler()" end |
- (void) handle(event = nil)
This method returns an undefined value.
Something has happened, so handle it.
48 49 50 51 52 53 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 48 def handle(event=nil) if event.class.method_defined?(:j_del) && !block_given? return @j_del.java_method(:handle, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(event.j_del) end raise ArgumentError, "Invalid arguments when calling handle(#{event})" end |
- (self) handler { ... }
150 151 152 153 154 155 156 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 150 def handler if block_given? @j_del.java_method(:handler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::JsonEvent)) })) return self end raise ArgumentError, "Invalid arguments when calling handler()" end |
- (self) object_event_mode
Flip the parser to emit a stream of events for each new json object.
85 86 87 88 89 90 91 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 85 def object_event_mode if !block_given? @j_del.java_method(:objectEventMode, []).call() return self end raise ArgumentError, "Invalid arguments when calling object_event_mode()" end |
- (self) object_value_mode
Flip the parser to emit a single value event for each new json object.
Json object currently streamed won't be affected.
96 97 98 99 100 101 102 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 96 def object_value_mode if !block_given? @j_del.java_method(:objectValueMode, []).call() return self end raise ArgumentError, "Invalid arguments when calling object_value_mode()" end |
- (self) pause
124 125 126 127 128 129 130 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 124 def pause if !block_given? @j_del.java_method(:pause, []).call() return self end raise ArgumentError, "Invalid arguments when calling pause()" end |
- (self) resume
132 133 134 135 136 137 138 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 132 def resume if !block_given? @j_del.java_method(:resume, []).call() return self end raise ArgumentError, "Invalid arguments when calling resume()" end |
- (self) write(buffer = nil)
Handle a
Buffer, pretty much like calling Proc#handle.
68 69 70 71 72 73 74 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/json_parser.rb', line 68 def write(buffer=nil) if buffer.class.method_defined?(:j_del) && !block_given? @j_del.java_method(:write, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(buffer.j_del) return self end raise ArgumentError, "Invalid arguments when calling write(#{buffer})" end |