Class List Method List File List

# Class: Vertx::AsyncFile

Inherits:
  Object
  - Object
  - Vertx::AsyncFile
  show all
Defined in:
  src/main/ruby_scripts/core/file_system.rb

## Overview

Represents a file on the file-system which can be read from, or written to asynchronously. Methods also exist to get a read stream or a write stream on the file. This allows the data to be pumped to and from other streams, e.g. an HttpClientRequest instance, using the Pump class

Author:

- Tim Fox

## Instance Method Summary (collapse)

- - (Object) close(&block)
  Close the file, asynchronously.
- - (Object) flush
  Flush any writes made to this file to underlying persistent storage, asynchronously.
- - (Object) read(buffer, offset, position, length, &block)
  Reads some data from a file into a buffer, asynchronously.
- - (ReadStream) read_stream
  A read stream operating on the file.
- - (Object) write(buffer, position, &block)
  Write a Buffer to the file, asynchronously.
- - (WriteStream) write_stream
  A write stream operating on the file.

## Instance Method Details

### - (`Object`) close(&block)

Close the file, asynchronously.

    108
    109
    110
    # File 'src/main/ruby_scripts/core/file_system.rb', line 108

    def close(&block)
      @j_file.close(FSWrappedHandler.new(block))
    end

### - (`Object`) flush

Flush any writes made to this file to underlying persistent storage, asynchronously. If the file was opened with flush set to true then calling this method will have no effect.

Parameters:

- hndlr (`Block`) —
  a block representing the handler which is called on completion.

    146
    147
    148
    # File 'src/main/ruby_scripts/core/file_system.rb', line 146

    def flush
      Future.new(@j_file.flush)
    end

### - (`Object`) read(buffer, offset, position, length, &block)

Reads some data from a file into a buffer, asynchronously. When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.

Parameters:

- buffer (`Buffer`) —
  The buffer into which the data which is read is written.
- offset (`FixNum`) —
  The position in the buffer where to start writing the data.
- position (`FixNum`) —
  The position in the file where to read the data.
- length (`FixNum`) —
  The number of bytes to read.

    129
    130
    131
    # File 'src/main/ruby_scripts/core/file_system.rb', line 129

    def read(buffer, offset, position, length, &block)
      @j_file.read(buffer._to_java_buffer, offset, position, length, FSWrappedHandler.new(block) { |j_buff| Buffer.new(j_buff) })
    end

### - (`ReadStream`) read_stream

A read stream operating on the file.

Returns:

- (`ReadStream`) —
  A read stream operating on the file.

    139
    140
    141
    # File 'src/main/ruby_scripts/core/file_system.rb', line 139

    def read_stream
      AsyncFileReadStream.new(@j_file.getReadStream)
    end

### - (`Object`) write(buffer, position, &block)

Write a Buffer to the file, asynchronously. When multiple writes are invoked on the same file there are no guarantees as to order in which those writes actually occur. starts with zero at the beginning of the file.

Parameters:

- buffer (`Buffer`) —
  The buffer to write
- position (`FixNum`) —
  The position in the file where to write the buffer. Position is measured in bytes and

    118
    119
    120
    # File 'src/main/ruby_scripts/core/file_system.rb', line 118

    def write(buffer, position, &block)
      @j_file.write(buffer._to_java_buffer, position, FSWrappedHandler.new(block))
    end

### - (`WriteStream`) write_stream

A write stream operating on the file.

Returns:

- (`WriteStream`) —
  A write stream operating on the file.

    134
    135
    136
    # File 'src/main/ruby_scripts/core/file_system.rb', line 134

    def write_stream
      AsyncFileWriteStream.new(@j_file.getWriteStream)
    end