Package: io.vertx.groovy.core.file

## [Groovy] Class AsyncFile

- io.vertx.groovy.core.file.AsyncFile

- All Implemented Interfaces and Traits:
    ReadStream, WriteStream

      @groovy.transform.CompileStatic
      class AsyncFile
      extends java.lang.Object

  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

- - ### Constructor Summary

    Constructors
    Constructor and description
    `AsyncFile (java.lang.Object delegate)`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `void` | `close()` Close the file.
    `void` | `close(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler)` Close the file.
    `AsyncFile` | `drainHandler(io.vertx.core.Handler<java.lang.Void> handler)`
    `void` | `end(Buffer t)` Same as AsyncFile.end but writes some data to the stream before ending.
    `void` | `end()` Close the file, see AsyncFile.close.
    `AsyncFile` | `endHandler(io.vertx.core.Handler<java.lang.Void> endHandler)`
    `AsyncFile` | `exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler)`
    `AsyncFile` | `flush()` Flush any writes made to this file to underlying persistent storage.
    `AsyncFile` | `flush(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler)` Same as AsyncFile.flush but the handler will be called when the flush is complete or if an error occurs
    `java.lang.Object` | `getDelegate()`
    `AsyncFile` | `handler(io.vertx.core.Handler<Buffer> handler)`
    `AsyncFile` | `pause()`
    `AsyncFile` | `read(Buffer buffer, int offset, long position, int length, io.vertx.core.Handler<io.vertx.core.AsyncResult<Buffer>> handler)` Reads `length` bytes of data from the file at position `position` in the file, asynchronously.
    `AsyncFile` | `resume()`
    `AsyncFile` | `setReadBufferSize(int readBufferSize)` Sets the buffer size that will be used to read the data from the file.
    `AsyncFile` | `setReadPos(long readPos)` Sets the position from which data will be read from when using the file as a ReadStream.
    `AsyncFile` | `setWritePos(long writePos)` Sets the position from which data will be written when using the file as a WriteStream.
    `AsyncFile` | `setWriteQueueMaxSize(int maxSize)`
    `AsyncFile` | `write(Buffer data)`
    `AsyncFile` | `write(Buffer buffer, long position, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler)` Write a Buffer to the file at position `position` in the file, asynchronously.
    `boolean` | `writeQueueFull()` This will return `true` if there are more bytes in the write queue than the value set using AsyncFile.setWriteQueueMaxSize

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Constructor Detail

    - #### AsyncFile(java.lang.Object delegate)

  - ### Method Detail

    - #### void close()

      Close the file. The actual close happens asynchronously.

    - #### void close(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler)

      Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.

      Parameters:
        `handler` - the handler

    - #### AsyncFile drainHandler(io.vertx.core.Handler<java.lang.Void> handler)

    - #### void end(Buffer t)

      Same as AsyncFile.end but writes some data to the stream before ending.

      Parameters:
        t

    - #### void end()

      Close the file, see AsyncFile.close.

    - #### AsyncFile endHandler(io.vertx.core.Handler<java.lang.Void> endHandler)

    - #### AsyncFile exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler)

    - #### AsyncFile flush()

      Flush any writes made to this file to underlying persistent storage.

      If the file was opened with `flush` set to `true` then calling this method will have no effect.

      The actual flush will happen asynchronously.

      Returns:
        a reference to this, so the API can be used fluently

    - #### AsyncFile flush(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler)

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

      Returns:
      Parameters:
        handler

    - #### java.lang.Object getDelegate()

    - #### AsyncFile handler(io.vertx.core.Handler<Buffer> handler)

    - #### AsyncFile pause()

    - #### AsyncFile read(Buffer buffer, int offset, long position, int length, io.vertx.core.Handler<io.vertx.core.AsyncResult<Buffer>> 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.

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `buffer` - the buffer to read into
        `offset` - the offset into the buffer where the data will be read
        `position` - the position in the file where to start reading
        `length` - the number of bytes to read
        `handler` - the handler to call when the write is complete

    - #### AsyncFile resume()

    - #### AsyncFile setReadBufferSize(int 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.

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `readBufferSize` - the buffer size

    - #### AsyncFile setReadPos(long readPos)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `readPos` - the position in the file

    - #### AsyncFile setWritePos(long writePos)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `writePos` - the position in the file

    - #### AsyncFile setWriteQueueMaxSize(int maxSize)

    - #### AsyncFile write(Buffer data)

    - #### AsyncFile write(Buffer buffer, long position, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler)

      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.

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `buffer` - the buffer to write
        `position` - the position in the file to write it at
        `handler` - the handler to call when the write is complete

    - #### boolean writeQueueFull()

      This will return `true` if there are more bytes in the write queue than the value set using AsyncFile.setWriteQueueMaxSize

      Returns:
        true if write queue is full