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)
34 35 36 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 34 def @@j_api_type.accept?(obj) obj.class == JsonParser end |
+ (Object) j_api_type
43 44 45 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 43 def self.j_api_type @@j_api_type end |
+ (Object) j_class
46 47 48 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 46 def self.j_class Java::IoVertxCoreParsetools::JsonParser.java_class end |
+ (::Vertx::JsonParser) new_parser(stream = nil)
Create a new
JsonParser
instance.
88 89 90 91 92 93 94 95 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 88 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)
40 41 42 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 40 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
37 38 39 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 37 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.
136 137 138 139 140 141 142 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 136 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.
147 148 149 150 151 152 153 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 147 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.
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 108 def end if !block_given? return @j_del.java_method(:end, []).call() end raise ArgumentError, "Invalid arguments when calling end()" end |
- (self) end_handler { ... }
181 182 183 184 185 186 187 |
# 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 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 { ... }
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 199 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)
172 173 174 175 176 177 178 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 172 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.
52 53 54 55 56 57 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 52 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 { ... }
190 191 192 193 194 195 196 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 190 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.
116 117 118 119 120 121 122 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 116 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.
127 128 129 130 131 132 133 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 127 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
155 156 157 158 159 160 161 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 155 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
.
62 63 64 65 66 67 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 62 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.
77 78 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 77 def pipe_to(dst=nil) if dst.class.method_defined?(:j_del) && !block_given? return @j_del.java_method(:pipeTo, [Java::IoVertxCoreStreams::WriteStream.java_class]).call(dst.j_del) elsif dst.class.method_defined?(:j_del) && block_given? 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) })) end raise ArgumentError, "Invalid arguments when calling pipe_to(#{dst})" end |
- (self) resume
163 164 165 166 167 168 169 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 163 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.
99 100 101 102 103 104 105 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/json_parser.rb', line 99 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 |