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(*args)
Create a new JsonParser instance.
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (self) arrayEventMode
Flip the parser to emit a stream of events for each new json array.
-
- (self) arrayValueMode
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) endHandler(endHandler) { ... }
- - (self) exceptionHandler(handler) { ... }
- - (self) fetch(amount)
-
- (void) handle(event)
Something has happened, so handle it.
- - (self) handler(handler) { ... }
-
- (self) objectEventMode
Flip the parser to emit a stream of events for each new json object.
-
- (self) objectValueMode
Flip the parser to emit a single value event for each new json object.
- - (self) pause
-
- (::Vertx::Pipe) pipe
Pause this stream and return a to transfer the elements of this stream to a destination .
-
- (void) pipeTo(dst, handler) { ... }
Pipe this ReadStream to the WriteStream.
- - (self) resume
-
- (self) write(buffer)
Handle a Buffer, pretty much like calling Proc#handle.
Class Method Details
+ (Boolean) accept?(obj)
36 37 38 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 36 def @@j_api_type.accept?(obj) obj.class == JsonParser end |
+ (Object) j_api_type
45 46 47 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 45 def self.j_api_type @@j_api_type end |
+ (Object) j_class
48 49 50 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 48 def self.j_class Java::IoVertxCoreParsetools::JsonParser.java_class end |
+ (::Vertx::JsonParser) newParser + (::Vertx::JsonParser) newParser(stream)
Create a new
JsonParser
instance.
97 98 99 100 101 102 103 104 105 106 107 108 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 97 def self.new_parser(*args) if !block_given? && args[0] == nil return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::JsonParser.java_method(:newParser, []).call(),::Vertx::JsonParser) elsif args[0].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(args[0].j_del),::Vertx::JsonParser) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling new_parser(#{args[0]})" end end |
+ (Object) unwrap(obj)
42 43 44 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 42 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
39 40 41 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 39 def @@j_api_type.wrap(obj) JsonParser.new(obj) end |
Instance Method Details
- (self) arrayEventMode
Flip the parser to emit a stream of events for each new json array.
125 126 127 128 129 130 131 132 133 134 135 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 125 def array_event_mode if !block_given? @j_del.java_method(:arrayEventMode, []).call() return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling array_event_mode()" end end |
- (self) arrayValueMode
Flip the parser to emit a single value event for each new json array.
Json array currently streamed won't be affected.
253 254 255 256 257 258 259 260 261 262 263 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 253 def array_value_mode if !block_given? @j_del.java_method(:arrayValueMode, []).call() return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling array_value_mode()" end end |
- (void) end
This method returns an undefined value.
End the stream, this must be called after all the json stream has been processed.
223 224 225 226 227 228 229 230 231 232 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 223 def end if !block_given? return @j_del.java_method(:end, []).call() end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling end()" end end |
- (self) endHandler(endHandler) { ... }
181 182 183 184 185 186 187 188 189 190 191 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 181 def end_handler if true @j_del.java_method(:endHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(nil) unless !block_given? })) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling end_handler()" end end |
- (self) exceptionHandler(handler) { ... }
267 268 269 270 271 272 273 274 275 276 277 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 267 def exception_handler if true @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) unless !block_given? })) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling exception_handler()" end end |
- (self) fetch(amount)
195 196 197 198 199 200 201 202 203 204 205 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 195 def fetch(*args) if args[0].class == Fixnum && !block_given? @j_del.java_method(:fetch, [Java::long.java_class]).call(args[0]) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling fetch(#{args[0]})" end end |
- (void) handle(event)
This method returns an undefined value.
Something has happened, so handle it.
82 83 84 85 86 87 88 89 90 91 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 82 def handle(*args) if args[0].class.method_defined?(:j_del) && !block_given? return @j_del.java_method(:handle, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(args[0].j_del) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling handle(#{args[0]})" end end |
- (self) handler(handler) { ... }
67 68 69 70 71 72 73 74 75 76 77 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 67 def handler if true @j_del.java_method(:handler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::JsonEvent)) unless !block_given? })) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling handler()" end end |
- (self) objectEventMode
Flip the parser to emit a stream of events for each new json object.
209 210 211 212 213 214 215 216 217 218 219 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 209 def object_event_mode if !block_given? @j_del.java_method(:objectEventMode, []).call() return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling object_event_mode()" end end |
- (self) objectValueMode
Flip the parser to emit a single value event for each new json object.
Json object currently streamed won't be affected.
141 142 143 144 145 146 147 148 149 150 151 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 141 def object_value_mode if !block_given? @j_del.java_method(:objectValueMode, []).call() return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling object_value_mode()" end end |
- (self) pause
111 112 113 114 115 116 117 118 119 120 121 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 111 def pause if !block_given? @j_del.java_method(:pause, []).call() return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling pause()" end end |
- (::Vertx::Pipe) pipe
Pause this stream and return a to transfer the elements of this stream to a destination .
The stream will be resumed when the pipe will be wired to a
WriteStream
.
238 239 240 241 242 243 244 245 246 247 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 238 def pipe if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:pipe, []).call(),::Vertx::Pipe,::Vertx::JsonEvent.j_api_type) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling pipe()" end end |
- (void) pipeTo(dst, handler) { ... }
This method returns an undefined value.
Pipe thisReadStream
to the WriteStream
.
Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Once this stream has ended or failed, the write stream will be ended and the handler
will be
called with the result.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 162 def pipe_to(*args) if args[0].class.method_defined?(:j_del) && true if (block_given?) return @j_del.java_method(:pipeTo, [Java::IoVertxCoreStreams::WriteStream.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0].j_del,block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise) else promise = ::Vertx::Util::Utils.promise @j_del.java_method(:pipeTo, [Java::IoVertxCoreStreams::WriteStream.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0].j_del,block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise) return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil) end end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling pipe_to(#{args[0]})" end end |
- (self) resume
53 54 55 56 57 58 59 60 61 62 63 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 53 def resume if !block_given? @j_del.java_method(:resume, []).call() return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling resume()" end end |
- (self) write(buffer)
Handle a
Buffer
, pretty much like calling Proc#handle.
282 283 284 285 286 287 288 289 290 291 292 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 282 def write(*args) if args[0].class.method_defined?(:j_del) && !block_given? @j_del.java_method(:write, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(args[0].j_del) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling write(#{args[0]})" end end |