Class: Vertx::JsonParser
- Inherits:
-
Object
- Object
- Vertx::JsonParser
- Includes:
- ReadStream
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/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 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 #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 { ... }
- - (self) fetch(amount = nil)
-
- (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)
32 33 34 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 32 def @@j_api_type.accept?(obj) obj.class == JsonParser end |
+ (Object) j_api_type
41 42 43 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 41 def self.j_api_type @@j_api_type end |
+ (Object) j_class
44 45 46 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 44 def self.j_class Java::IoVertxCoreParsetools::JsonParser.java_class end |
+ (::Vertx::JsonParser) new_parser(stream = nil)
Create a new
JsonParser
instance.
59 60 61 62 63 64 65 66 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 59 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)
38 39 40 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 38 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
35 36 37 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 35 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.
107 108 109 110 111 112 113 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 107 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.
118 119 120 121 122 123 124 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 118 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.
79 80 81 82 83 84 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 79 def end if !block_given? return @j_del.java_method(:end, []).call() end raise ArgumentError, "Invalid arguments when calling end()" end |
- (self) end_handler { ... }
152 153 154 155 156 157 158 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 152 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 { ... }
170 171 172 173 174 175 176 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 170 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 |
- (self) fetch(amount = nil)
143 144 145 146 147 148 149 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 143 def fetch(amount=nil) if amount.class == Fixnum && !block_given? @j_del.java_method(:fetch, [Java::long.java_class]).call(amount) return self end raise ArgumentError, "Invalid arguments when calling fetch(#{amount})" end |
- (void) handle(event = nil)
This method returns an undefined value.
Something has happened, so handle it.
50 51 52 53 54 55 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 50 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 { ... }
161 162 163 164 165 166 167 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 161 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.
87 88 89 90 91 92 93 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 87 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.
98 99 100 101 102 103 104 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 98 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
126 127 128 129 130 131 132 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 126 def pause if !block_given? @j_del.java_method(:pause, []).call() return self end raise ArgumentError, "Invalid arguments when calling pause()" end |
- (self) resume
134 135 136 137 138 139 140 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 134 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.
70 71 72 73 74 75 76 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 70 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 |