Class: Vertx::AsyncFile

Inherits:
Object
  • Object
show all
Includes:
ReadStream, WriteStream
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb

Overview

Represents a file on the file-system which can be read from, or written to asynchronously.

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)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


30
31
32
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 30

def @@j_api_type.accept?(obj)
  obj.class == AsyncFile
end

+ (Object) j_api_type



39
40
41
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 39

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



42
43
44
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 42

def self.j_class
  Java::IoVertxCoreFile::AsyncFile.java_class
end

+ (Object) unwrap(obj)



36
37
38
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 36

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



33
34
35
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 33

def @@j_api_type.wrap(obj)
  AsyncFile.new(obj)
end

Instance Method Details

- (void) close(handler) { ... }

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.

Yields:

  • the handler


342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 342

def close
  if true
    if (block_given?)
      return @j_del.java_method(:close, [Java::IoVertxCore::Handler.java_class]).call(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(:close, [Java::IoVertxCore::Handler.java_class]).call(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 close()"
  end
end

- (self) drainHandler(handler) { ... }

Yields:

Returns:

  • (self)


252
253
254
255
256
257
258
259
260
261
262
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 252

def drain_handler
  if true
    @j_del.java_method(:drainHandler, [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 drain_handler()"
  end
end

- (void) end(handler) { ... } - (void) end(data, handler) { ... }

This method returns an undefined value.

Same as but with an handler called when the operation completes

Overloads:

  • - (void) end(handler) { ... }

    Yields:

  • - (void) end(data, handler) { ... }

    Parameters:

    Yields:



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 313

def end(*args)
  if true && args[0] == nil
    if (block_given?)
      return @j_del.java_method(:end, [Java::IoVertxCore::Handler.java_class]).call(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(:end, [Java::IoVertxCore::Handler.java_class]).call(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
  elsif args[0].class.method_defined?(:j_del) && true
    if (block_given?)
      return @j_del.java_method(:end, [Java::IoVertxCoreBuffer::Buffer.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(:end, [Java::IoVertxCoreBuffer::Buffer.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 end(#{args[0]})"
  end
end

- (self) endHandler(endHandler) { ... }

Yields:

Returns:

  • (self)


266
267
268
269
270
271
272
273
274
275
276
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 266

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) { ... }

Yields:

Returns:

  • (self)


361
362
363
364
365
366
367
368
369
370
371
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 361

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)

Parameters:

  • amount (Fixnum)

Returns:

  • (self)


280
281
282
283
284
285
286
287
288
289
290
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 280

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

- (self) flush(handler) { ... }

Same as #flush but the handler will be called when the flush is complete or if an error occurs

Yields:

Returns:

  • (self)


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 232

def flush
  if true
    if (block_given?)
      @j_del.java_method(:flush, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise)
      return self
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:flush, [Java::IoVertxCore::Handler.java_class]).call(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 flush()"
  end
end

- (Fixnum) getWritePos

Returns the current write position the file is at

Returns:

  • (Fixnum)
    the current write position the file is at


63
64
65
66
67
68
69
70
71
72
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 63

def get_write_pos
  if !block_given?
    return @j_del.java_method(:getWritePos, []).call()
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling get_write_pos()"
  end
end

- (self) handler(handler) { ... }

Yields:

Returns:

  • (self)


89
90
91
92
93
94
95
96
97
98
99
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 89

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::Buffer)) unless !block_given? }))
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling handler()"
  end
end

- (self) pause

Returns:

  • (self)


161
162
163
164
165
166
167
168
169
170
171
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 161

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.

Returns:



296
297
298
299
300
301
302
303
304
305
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 296

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
  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 this ReadStream 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.

Parameters:

Yields:



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 197

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) read(buffer, offset, position, length, handler) { ... }

Reads 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.

Parameters:

  • buffer (::Vertx::Buffer)
    the buffer to read into
  • offset (Fixnum)
    the offset into the buffer where the data will be read
  • position (Fixnum)
    the position in the file where to start reading
  • length (Fixnum)
    the number of bytes to read

Yields:

  • the handler to call when the write is complete

Returns:

  • (self)


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 115

def read(*args)
  if args[0].class.method_defined?(:j_del) && args[1].class == Fixnum && args[2].class == Fixnum && args[3].class == Fixnum && true
    if (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(args[0].j_del,args[1],args[2],args[3],block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Buffer) : nil) } : promise)
      return self
    else
      promise = ::Vertx::Util::Utils.promise
      @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(args[0].j_del,args[1],args[2],args[3],block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Buffer) : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future,::Vertx::Buffer.j_api_type)
    end
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling read(#{args[0]},#{args[1]},#{args[2]},#{args[3]})"
  end
end

- (self) resume

Returns:

  • (self)


75
76
77
78
79
80
81
82
83
84
85
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 75

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) setReadBufferSize(readBufferSize)

Sets the buffer size that will be used to read the data from the file. Changing this value will impact how much the data will be read at a time from the file system.

Parameters:

  • readBufferSize (Fixnum)
    the buffer size

Returns:

  • (self)


50
51
52
53
54
55
56
57
58
59
60
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 50

def set_read_buffer_size(*args)
  if args[0].class == Fixnum && !block_given?
    @j_del.java_method(:setReadBufferSize, [Java::int.java_class]).call(args[0])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling set_read_buffer_size(#{args[0]})"
  end
end

- (self) setReadLength(readLength)

Sets the number of bytes that will be read when using the file as a ReadStream.

Parameters:

  • readLength (Fixnum)
    the bytes that will be read from the file

Returns:

  • (self)


176
177
178
179
180
181
182
183
184
185
186
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 176

def set_read_length(*args)
  if args[0].class == Fixnum && !block_given?
    @j_del.java_method(:setReadLength, [Java::long.java_class]).call(args[0])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling set_read_length(#{args[0]})"
  end
end

- (self) setReadPos(readPos)

Sets the position from which data will be read from when using the file as a ReadStream.

Parameters:

  • readPos (Fixnum)
    the position in the file

Returns:

  • (self)


417
418
419
420
421
422
423
424
425
426
427
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 417

def set_read_pos(*args)
  if args[0].class == Fixnum && !block_given?
    @j_del.java_method(:setReadPos, [Java::long.java_class]).call(args[0])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling set_read_pos(#{args[0]})"
  end
end

- (self) setWritePos(writePos)

Sets the position from which data will be written when using the file as a WriteStream.

Parameters:

  • writePos (Fixnum)
    the position in the file

Returns:

  • (self)


217
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 217

def set_write_pos(*args)
  if args[0].class == Fixnum && !block_given?
    @j_del.java_method(:setWritePos, [Java::long.java_class]).call(args[0])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling set_write_pos(#{args[0]})"
  end
end

- (self) setWriteQueueMaxSize(maxSize)

Parameters:

  • maxSize (Fixnum)

Returns:

  • (self)


148
149
150
151
152
153
154
155
156
157
158
# 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(*args)
  if args[0].class == Fixnum && !block_given?
    @j_del.java_method(:setWriteQueueMaxSize, [Java::int.java_class]).call(args[0])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling set_write_queue_max_size(#{args[0]})"
  end
end

- (void) write(data, handler) { ... } - (void) write(buffer, position, handler) { ... }

This method returns an undefined value.

Write a Buffer to the file at position 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.

Overloads:

  • - (void) write(data, handler) { ... }

    Parameters:

    Yields:

  • - (void) write(buffer, position, handler) { ... }

    Parameters:

    • buffer (::Vertx::Buffer)
      the buffer to write
    • position (Fixnum)
      the position in the file to write it at

    Yields:

    • the handler to call when the write is complete


389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 389

def write(*args)
  if args[0].class.method_defined?(:j_del) && true && args[1] == nil
    if (block_given?)
      return @j_del.java_method(:write, [Java::IoVertxCoreBuffer::Buffer.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(:write, [Java::IoVertxCoreBuffer::Buffer.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
  elsif args[0].class.method_defined?(:j_del) && args[1].class == Fixnum && true
    if (block_given?)
      return @j_del.java_method(:write, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::long.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0].j_del,args[1],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(:write, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::long.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0].j_del,args[1],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 write(#{args[0]},#{args[1]})"
  end
end

- (true, false) writeQueueFull

This will return true if there are more bytes in the write queue than the value set using #set_write_queue_max_size

Returns:

  • (true, false)
    true if write queue is full


135
136
137
138
139
140
141
142
143
144
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/async_file.rb', line 135

def write_queue_full?
  if !block_given?
    return @j_del.java_method(:writeQueueFull, []).call()
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling write_queue_full?()"
  end
end