Class AsyncFile

java.lang.Object
io.vertx.mutiny.core.file.AsyncFile
All Implemented Interfaces:
MutinyDelegate, ReadStream<Buffer>, StreamBase, WriteStream<Buffer>

public class AsyncFile extends Object implements MutinyDelegate, ReadStream<Buffer>, WriteStream<Buffer>
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 piped to and from other streams, e.g. an HttpClientRequest instance, using the Pipe class

NOTE: This class has been automatically generated from the original non Mutiny-ified interface using Vert.x codegen.

  • Field Details

  • Constructor Details

    • AsyncFile

      public AsyncFile(io.vertx.core.file.AsyncFile delegate)
    • AsyncFile

      public AsyncFile(Object delegate)
  • Method Details

    • getDelegate

      public io.vertx.core.file.AsyncFile getDelegate()
      Specified by:
      getDelegate in interface MutinyDelegate
      Specified by:
      getDelegate in interface ReadStream<Buffer>
      Specified by:
      getDelegate in interface StreamBase
      Specified by:
      getDelegate in interface WriteStream<Buffer>
      Returns:
      the delegate used by this Mutiny object of generated type
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toSubscriber

      @CheckReturnValue public WriteStreamSubscriber<Buffer> toSubscriber()
    • write

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> write(Buffer data)
      Same as but with an handler called when the operation completes

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Specified by:
      write in interface WriteStream<Buffer>
      Parameters:
      data -
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • writeAndAwait

      public Void writeAndAwait(Buffer data)
      Blocking variant of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Specified by:
      writeAndAwait in interface WriteStream<Buffer>
      Parameters:
      data -
      Returns:
      the Void instance produced by the operation.
    • writeAndForget

      public void writeAndForget(Buffer data)
      Variant of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer) that ignores the result of the operation.

      This method subscribes on the result of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer) but you don't need to compose it with other operations.

      Specified by:
      writeAndForget in interface WriteStream<Buffer>
      Parameters:
      data -
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end()
      Same as WriteStream.end() but with an handler called when the operation completes

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Specified by:
      end in interface WriteStream<Buffer>
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • endAndAwait

      public Void endAndAwait()
      Blocking variant of WriteStream.end().

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Specified by:
      endAndAwait in interface WriteStream<Buffer>
      Returns:
      the Void instance produced by the operation.
    • endAndForget

      public void endAndForget()
      Variant of WriteStream.end() that ignores the result of the operation.

      This method subscribes on the result of WriteStream.end(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from WriteStream.end() but you don't need to compose it with other operations.

      Specified by:
      endAndForget in interface WriteStream<Buffer>
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end(Buffer data)
      Same as but with an handler called when the operation completes

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Specified by:
      end in interface WriteStream<Buffer>
      Parameters:
      data -
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • endAndAwait

      public Void endAndAwait(Buffer data)
      Blocking variant of io.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Specified by:
      endAndAwait in interface WriteStream<Buffer>
      Parameters:
      data -
      Returns:
      the Void instance produced by the operation.
    • endAndForget

      public void endAndForget(Buffer data)
      Variant of io.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer) that ignores the result of the operation.

      This method subscribes on the result of io.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer) but you don't need to compose it with other operations.

      Specified by:
      endAndForget in interface WriteStream<Buffer>
      Parameters:
      data -
    • writeQueueFull

      public boolean writeQueueFull()
      Specified by:
      writeQueueFull in interface WriteStream<Buffer>
      Returns:
      true if write queue is full
    • pipe

      public Pipe<Buffer> pipe()
      Specified by:
      pipe in interface ReadStream<Buffer>
      Returns:
      a pipe
    • pipeTo

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<Buffer> dst)
      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.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Specified by:
      pipeTo in interface ReadStream<Buffer>
      Parameters:
      dst - the destination write stream
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • pipeToAndAwait

      public Void pipeToAndAwait(WriteStream<Buffer> dst)
      Blocking variant of ReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Specified by:
      pipeToAndAwait in interface ReadStream<Buffer>
      Parameters:
      dst - the destination write stream
      Returns:
      the Void instance produced by the operation.
    • pipeToAndForget

      public void pipeToAndForget(WriteStream<Buffer> dst)
      Variant of ReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream) that ignores the result of the operation.

      This method subscribes on the result of ReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from ReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream) but you don't need to compose it with other operations.

      Specified by:
      pipeToAndForget in interface ReadStream<Buffer>
      Parameters:
      dst - the destination write stream
    • handler

      public AsyncFile handler(Consumer<Buffer> handler)
      Specified by:
      handler in interface ReadStream<Buffer>
      Returns:
    • pause

      public AsyncFile pause()
      Specified by:
      pause in interface ReadStream<Buffer>
      Returns:
      a reference to this, so the API can be used fluently
    • resume

      public AsyncFile resume()
      Specified by:
      resume in interface ReadStream<Buffer>
      Returns:
      a reference to this, so the API can be used fluently
    • endHandler

      public AsyncFile endHandler(Runnable endHandler)
      Specified by:
      endHandler in interface ReadStream<Buffer>
      Returns:
    • setWriteQueueMaxSize

      public AsyncFile setWriteQueueMaxSize(int maxSize)
      Specified by:
      setWriteQueueMaxSize in interface WriteStream<Buffer>
      Parameters:
      maxSize - the max size of the write stream
      Returns:
      a reference to this, so the API can be used fluently
    • drainHandler

      public AsyncFile drainHandler(Runnable handler)
      Specified by:
      drainHandler in interface WriteStream<Buffer>
      Parameters:
      handler - the handler
      Returns:
    • exceptionHandler

      public AsyncFile exceptionHandler(Consumer<Throwable> handler)
      Specified by:
      exceptionHandler in interface ReadStream<Buffer>
      Specified by:
      exceptionHandler in interface StreamBase
      Specified by:
      exceptionHandler in interface WriteStream<Buffer>
      Parameters:
      handler - the exception handler
      Returns:
    • fetch

      public AsyncFile fetch(long amount)
      Specified by:
      fetch in interface ReadStream<Buffer>
      Returns:
      a reference to this, so the API can be used fluently
    • close

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> close()
      Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • closeAndAwait

      public Void closeAndAwait()
      Blocking variant of close().

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Returns:
      the Void instance produced by the operation.
    • closeAndForget

      public void closeAndForget()
      Variant of close() that ignores the result of the operation.

      This method subscribes on the result of close(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from close() but you don't need to compose it with other operations.

    • write

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> write(Buffer buffer, long position)
      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.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Parameters:
      buffer - the buffer to write
      position - the position in the file to write it at
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • writeAndAwait

      public Void writeAndAwait(Buffer buffer, long position)
      Blocking variant of write(io.vertx.mutiny.core.buffer.Buffer,long).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      buffer - the buffer to write
      position - the position in the file to write it at
      Returns:
      the Void instance produced by the operation.
    • writeAndForget

      public void writeAndForget(Buffer buffer, long position)
      Variant of write(io.vertx.mutiny.core.buffer.Buffer,long) that ignores the result of the operation.

      This method subscribes on the result of write(io.vertx.mutiny.core.buffer.Buffer,long), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from write(io.vertx.mutiny.core.buffer.Buffer,long) but you don't need to compose it with other operations.

      Parameters:
      buffer - the buffer to write
      position - the position in the file to write it at
    • read

      @CheckReturnValue public io.smallrye.mutiny.Uni<Buffer> read(Buffer buffer, int offset, long position, int length)
      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.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      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
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • readAndAwait

      public Buffer readAndAwait(Buffer buffer, int offset, long position, int length)
      Blocking variant of read(io.vertx.mutiny.core.buffer.Buffer,int,long,int).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      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
      Returns:
      the Buffer instance produced by the operation.
    • readAndForget

      public AsyncFile readAndForget(Buffer buffer, int offset, long position, int length)
      Variant of read(io.vertx.mutiny.core.buffer.Buffer,int,long,int) that ignores the result of the operation.

      This method subscribes on the result of read(io.vertx.mutiny.core.buffer.Buffer,int,long,int), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from read(io.vertx.mutiny.core.buffer.Buffer,int,long,int) but you don't need to compose it with other operations.

      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
      Returns:
      the instance of AsyncFile to chain method calls.
    • flush

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> flush()
      Same as flush() but the handler will be called when the flush is complete or if an error occurs

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • flushAndAwait

      public Void flushAndAwait()
      Blocking variant of flush().

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Returns:
      the Void instance produced by the operation.
    • flushAndForget

      public AsyncFile flushAndForget()
      Variant of flush() that ignores the result of the operation.

      This method subscribes on the result of flush(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from flush() but you don't need to compose it with other operations.

      Returns:
      the instance of AsyncFile to chain method calls.
    • setReadPos

      public AsyncFile setReadPos(long readPos)
      Parameters:
      readPos - the position in the file
      Returns:
      a reference to this, so the API can be used fluently
    • setReadLength

      public AsyncFile setReadLength(long readLength)
      Parameters:
      readLength - the bytes that will be read from the file
      Returns:
      a reference to this, so the API can be used fluently
    • getReadLength

      public long getReadLength()
      Returns:
      the number of bytes that will be read when using the file as a ReadStream
    • setWritePos

      public AsyncFile setWritePos(long writePos)
      Parameters:
      writePos - the position in the file
      Returns:
      a reference to this, so the API can be used fluently
    • getWritePos

      public long getWritePos()
      Returns:
      the current write position the file is at
    • setReadBufferSize

      public AsyncFile setReadBufferSize(int readBufferSize)
      Parameters:
      readBufferSize - the buffer size
      Returns:
      a reference to this, so the API can be used fluently
    • sizeBlocking

      public long sizeBlocking()
      Returns:
    • size

      @CheckReturnValue public io.smallrye.mutiny.Uni<Long> size()
      Like size() but the handler will be called when the operation is complete or if an error occurs.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • sizeAndAwait

      public Long sizeAndAwait()
      Blocking variant of size().

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Returns:
      the Long instance produced by the operation.
    • sizeAndForget

      public void sizeAndForget()
      Variant of size() that ignores the result of the operation.

      This method subscribes on the result of size(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from size() but you don't need to compose it with other operations.

    • tryLock

      public AsyncFileLock tryLock()
      Returns:
      the lock if it can be acquired immediately, otherwise null
    • tryLock

      public AsyncFileLock tryLock(long position, long size, boolean shared)
      Parameters:
      position - where the region starts
      size - the size of the region
      shared - whether the lock should be shared
      Returns:
      the lock if it can be acquired immediately, otherwise null
    • lock

      @CheckReturnValue public io.smallrye.mutiny.Uni<AsyncFileLock> lock()
      Like lock() but the handler will be called when the operation is complete or if an error occurs.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • lockAndAwait

      public AsyncFileLock lockAndAwait()
      Blocking variant of lock().

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Returns:
      the AsyncFileLock instance produced by the operation.
    • lockAndForget

      public void lockAndForget()
      Variant of lock() that ignores the result of the operation.

      This method subscribes on the result of lock(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from lock() but you don't need to compose it with other operations.

    • lock

      @CheckReturnValue public io.smallrye.mutiny.Uni<AsyncFileLock> lock(long position, long size, boolean shared)
      Like lock() but the handler will be called when the operation is complete or if an error occurs.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Parameters:
      position -
      size -
      shared -
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • lockAndAwait

      public AsyncFileLock lockAndAwait(long position, long size, boolean shared)
      Blocking variant of lock(long,long,boolean).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      position -
      size -
      shared -
      Returns:
      the AsyncFileLock instance produced by the operation.
    • lockAndForget

      public void lockAndForget(long position, long size, boolean shared)
      Variant of lock(long,long,boolean) that ignores the result of the operation.

      This method subscribes on the result of lock(long,long,boolean), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from lock(long,long,boolean) but you don't need to compose it with other operations.

      Parameters:
      position -
      size -
      shared -
    • toMulti

      @CheckReturnValue public io.smallrye.mutiny.Multi<Buffer> toMulti()
      Specified by:
      toMulti in interface ReadStream<Buffer>
    • toBlockingIterable

      public Iterable<Buffer> toBlockingIterable()
    • toBlockingStream

      public Stream<Buffer> toBlockingStream()
    • newInstance

      public static AsyncFile newInstance(io.vertx.core.file.AsyncFile arg)