Class: Vertx::AsyncFile

Inherits:
Object
  • Object
show all
Includes:
ReadStream, WriteStream
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/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

Instance Method Summary (collapse)

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.

Yields:

  • the handler

Raises:

  • (ArgumentError)


122
123
124
125
126
127
128
129
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 122

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

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


102
103
104
105
106
107
108
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 102

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

- (self) end_handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 61

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

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


111
112
113
114
115
116
117
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 111

def exception_handler
  if block_given?
    @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling exception_handler()"
end

- (self) flush { ... }

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

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


154
155
156
157
158
159
160
161
162
163
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 154

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

- (self) handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 36

def handler
  if block_given?
    @j_del.java_method(:handler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Buffer.new(event)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling handler()"
end

- (self) pause

Returns:

  • (self)

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 44

def pause
  if !block_given?
    @j_del.java_method(:pause, []).call()
    return self
  end
  raise ArgumentError, "Invalid arguments when calling pause()"
end

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

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) (defaults to: nil)
    the buffer to read into
  • offset (Fixnum) (defaults to: nil)
    the offset into the buffer where the data will be read
  • position (Fixnum) (defaults to: nil)
    the position in the file where to start reading
  • length (Fixnum) (defaults to: nil)
    the number of bytes to read

Yields:

  • the handler to call when the write is complete

Returns:

  • (self)

Raises:

  • (ArgumentError)


144
145
146
147
148
149
150
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 144

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::Buffer.new(ar.result) : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling read(buffer,offset,position,length)"
end

- (self) resume

Returns:

  • (self)

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 52

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_pos(readPos = nil)

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

Parameters:

  • readPos (Fixnum) (defaults to: nil)
    the position in the file

Returns:

  • (self)

Raises:

  • (ArgumentError)


167
168
169
170
171
172
173
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 167

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)

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

Parameters:

  • writePos (Fixnum) (defaults to: nil)
    the position in the file

Returns:

  • (self)

Raises:

  • (ArgumentError)


177
178
179
180
181
182
183
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 177

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)

Parameters:

  • maxSize (Fixnum) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)


93
94
95
96
97
98
99
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 93

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

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.

Parameters:

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

Yields:

  • the handler to call when the write is complete

Returns:

  • (self)

Raises:

  • (ArgumentError)


81
82
83
84
85
86
87
88
89
90
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 81

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?

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

Raises:

  • (ArgumentError)


28
29
30
31
32
33
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/async_file.rb', line 28

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