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
-
- (::Vertx::Pipe) pipe
Pause this stream and return a to transfer the elements of this stream to a destination .
-
- (void) pipe_to(dst = nil) { ... }
Pipe this ReadStream to the WriteStream.
- - (self) resume
-
- (self) write(buffer = nil)
Handle a Buffer, pretty much like calling Proc#handle.
Class Method Details
+ (Boolean) accept?(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.accept?(obj) obj.class == JsonParser end |
+ (Object) j_api_type
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_api_type @@j_api_type end |
+ (Object) j_class
47 48 49 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 47 def self.j_class Java::IoVertxCoreParsetools::JsonParser.java_class end |
+ (::Vertx::JsonParser) new_parser(stream = nil)
Create a new
JsonParser instance.
87 88 89 90 91 92 93 94 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 87 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)
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 @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(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.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.
135 136 137 138 139 140 141 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 135 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.
146 147 148 149 150 151 152 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 146 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.
107 108 109 110 111 112 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 107 def end if !block_given? return @j_del.java_method(:end, []).call() end raise ArgumentError, "Invalid arguments when calling end()" end |
- (self) end_handler { ... }
180 181 182 183 184 185 186 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 180 def end_handler if true @j_del.java_method(:endHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield unless !block_given? }) return self end raise ArgumentError, "Invalid arguments when calling end_handler()" end |
- (self) exception_handler { ... }
198 199 200 201 202 203 204 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 198 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 raise ArgumentError, "Invalid arguments when calling exception_handler()" end |
- (self) fetch(amount = nil)
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 171 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.
53 54 55 56 57 58 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 53 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 { ... }
189 190 191 192 193 194 195 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 189 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 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.
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 115 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.
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 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
154 155 156 157 158 159 160 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 154 def pause if !block_given? @j_del.java_method(:pause, []).call() return self end raise ArgumentError, "Invalid arguments when calling pause()" 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.
63 64 65 66 67 68 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 63 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 raise ArgumentError, "Invalid arguments when calling pipe()" end |
- (void) pipe_to(dst = nil) { ... }
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.
78 79 80 81 82 83 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 78 def pipe_to(dst=nil) if dst.class.method_defined?(:j_del) && true return @j_del.java_method(:pipeTo, [Java::IoVertxCoreStreams::WriteStream.java_class,Java::IoVertxCore::Handler.java_class]).call(dst.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) } unless !block_given?)) end raise ArgumentError, "Invalid arguments when calling pipe_to(#{dst})" end |
- (self) resume
162 163 164 165 166 167 168 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 162 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.
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 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 |