Class: Vertx::AsyncFile
- Inherits:
-
Object
- Object
- Vertx::AsyncFile
- Includes:
- ReadStream, WriteStream
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb
Overview
This class also implements ReadStream and WriteStream. This allows the data to be pumped to and from other streams, e.g. an HttpClientRequest instance, using the Pump class
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary (collapse)
- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (void) close { ... }
Close the file.
- - (self) drain_handler { ... }
-
- (void) end(t = nil)
Same as #end but writes some data to the stream before ending.
- - (self) end_handler { ... }
- - (self) exception_handler { ... }
- - (self) fetch(amount = nil)
-
- (self) flush { ... }
Same as #flush but the handler will be called when the flush is complete or if an error occurs.
-
- (Fixnum) get_write_pos
The current write position the file is at.
- - (self) handler { ... }
- - (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) read(buffer = nil, offset = nil, position = nil, length = nil) { ... }
Reads length bytes of data from the file at position position in the file, asynchronously.
- - (self) resume
-
- (self) set_read_buffer_size(readBufferSize = nil)
Sets the buffer size that will be used to read the data from the file.
-
- (self) set_read_pos(readPos = nil)
Sets the position from which data will be read from when using the file as a ReadStream.
-
- (self) set_write_pos(writePos = nil)
Sets the position from which data will be written when using the file as a WriteStream.
- - (self) set_write_queue_max_size(maxSize = nil)
-
- (self) write(buffer = nil, position = nil) { ... }
Write a Buffer to the file at position position in the file, asynchronously.
-
- (true, false) write_queue_full?
This will return true if there are more bytes in the write queue than the value set using #set_write_queue_max_size.
Class Method Details
+ (Boolean) accept?(obj)
28 29 30 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 28 def @@j_api_type.accept?(obj) obj.class == AsyncFile end |
+ (Object) j_api_type
37 38 39 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 37 def self.j_api_type @@j_api_type end |
+ (Object) j_class
40 41 42 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 40 def self.j_class Java::IoVertxCoreFile::AsyncFile.java_class end |
+ (Object) unwrap(obj)
34 35 36 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 34 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
31 32 33 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 31 def @@j_api_type.wrap(obj) AsyncFile.new(obj) end |
Instance Method Details
- (void) close { ... }
This method returns an undefined value.
Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.
186 187 188 189 190 191 192 193 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 186 def close if !block_given? return @j_del.java_method(:close, []).call() elsif block_given? return @j_del.java_method(:close, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil) })) end raise ArgumentError, "Invalid arguments when calling close()" end |
- (self) drain_handler { ... }
157 158 159 160 161 162 163 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 157 def drain_handler if block_given? @j_del.java_method(:drainHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield }) return self end raise ArgumentError, "Invalid arguments when calling drain_handler()" end |
- (void) end(t = nil)
This method returns an undefined value.
Same as #end but writes some data to the stream before ending.
46 47 48 49 50 51 52 53 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 46 def end(t=nil) if !block_given? && t == nil return @j_del.java_method(:end, []).call() elsif t.class.method_defined?(:j_del) && !block_given? return @j_del.java_method(:end, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(t.j_del) end raise ArgumentError, "Invalid arguments when calling end(#{t})" end |
- (self) end_handler { ... }
116 117 118 119 120 121 122 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 116 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 { ... }
166 167 168 169 170 171 172 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 166 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)
175 176 177 178 179 180 181 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 175 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 |
- (self) flush { ... }
218 219 220 221 222 223 224 225 226 227 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 218 def flush if !block_given? @j_del.java_method(:flush, []).call() return self elsif block_given? @j_del.java_method(:flush, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil) })) return self end raise ArgumentError, "Invalid arguments when calling flush()" end |
- (Fixnum) get_write_pos
249 250 251 252 253 254 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 249 def get_write_pos if !block_given? return @j_del.java_method(:getWritePos, []).call() end raise ArgumentError, "Invalid arguments when calling get_write_pos()" end |
- (self) handler { ... }
91 92 93 94 95 96 97 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 91 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::Buffer)) })) return self end raise ArgumentError, "Invalid arguments when calling handler()" end |
- (self) pause
99 100 101 102 103 104 105 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 99 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
WriteStream
.
66 67 68 69 70 71 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 66 def pipe if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:pipe, []).call(),::Vertx::Pipe,::Vertx::Buffer.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.
81 82 83 84 85 86 87 88 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 81 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) read(buffer = nil, offset = nil, position = nil, length = nil) { ... }
length
bytes of data from the file at position position
in the file, asynchronously.
The read data will be written into the specified Buffer buffer
at position offset
.
If data is read past the end of the file then zero bytes will be read.
When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.
The handler will be called when the close is complete, or if an error occurs.
208 209 210 211 212 213 214 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 208 def read(buffer=nil,offset=nil,position=nil,length=nil) if buffer.class.method_defined?(:j_del) && offset.class == Fixnum && position.class == Fixnum && length.class == Fixnum && block_given? @j_del.java_method(:read, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::int.java_class,Java::long.java_class,Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(buffer.j_del,offset,position,length,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Buffer) : nil) })) return self end raise ArgumentError, "Invalid arguments when calling read(#{buffer},#{offset},#{position},#{length})" end |
- (self) resume
107 108 109 110 111 112 113 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 107 def resume if !block_given? @j_del.java_method(:resume, []).call() return self end raise ArgumentError, "Invalid arguments when calling resume()" end |
- (self) set_read_buffer_size(readBufferSize = nil)
259 260 261 262 263 264 265 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 259 def set_read_buffer_size(readBufferSize=nil) if readBufferSize.class == Fixnum && !block_given? @j_del.java_method(:setReadBufferSize, [Java::int.java_class]).call(readBufferSize) return self end raise ArgumentError, "Invalid arguments when calling set_read_buffer_size(#{readBufferSize})" end |
- (self) set_read_pos(readPos = nil)
231 232 233 234 235 236 237 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 231 def set_read_pos(readPos=nil) if readPos.class == Fixnum && !block_given? @j_del.java_method(:setReadPos, [Java::long.java_class]).call(readPos) return self end raise ArgumentError, "Invalid arguments when calling set_read_pos(#{readPos})" end |
- (self) set_write_pos(writePos = nil)
241 242 243 244 245 246 247 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 241 def set_write_pos(writePos=nil) if writePos.class == Fixnum && !block_given? @j_del.java_method(:setWritePos, [Java::long.java_class]).call(writePos) return self end raise ArgumentError, "Invalid arguments when calling set_write_pos(#{writePos})" end |
- (self) set_write_queue_max_size(maxSize = nil)
148 149 150 151 152 153 154 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 148 def set_write_queue_max_size(maxSize=nil) if maxSize.class == Fixnum && !block_given? @j_del.java_method(:setWriteQueueMaxSize, [Java::int.java_class]).call(maxSize) return self end raise ArgumentError, "Invalid arguments when calling set_write_queue_max_size(#{maxSize})" end |
- (self) write(buffer = nil, position = nil) { ... }
position
in the file, asynchronously.
If position
lies outside of the current size
of the file, the file will be enlarged to encompass it.
When multiple writes are invoked on the same file there are no guarantees as to order in which those writes actually occur
The handler will be called when the write is complete, or if an error occurs.
136 137 138 139 140 141 142 143 144 145 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 136 def write(buffer=nil,position=nil) if buffer.class.method_defined?(:j_del) && !block_given? && position == nil @j_del.java_method(:write, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(buffer.j_del) return self elsif buffer.class.method_defined?(:j_del) && position.class == Fixnum && block_given? @j_del.java_method(:write, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::long.java_class,Java::IoVertxCore::Handler.java_class]).call(buffer.j_del,position,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) })) return self end raise ArgumentError, "Invalid arguments when calling write(#{buffer},#{position})" end |
- (true, false) write_queue_full?
true
if there are more bytes in the write queue than the value set using #set_write_queue_max_size
56 57 58 59 60 61 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 56 def write_queue_full? if !block_given? return @j_del.java_method(:writeQueueFull, []).call() end raise ArgumentError, "Invalid arguments when calling write_queue_full?()" end |