Class AsyncFile
- java.lang.Object
-
- io.vertx.mutiny.core.file.AsyncFile
-
- All Implemented Interfaces:
ReadStream<Buffer>
,StreamBase
,WriteStream<Buffer>
public class AsyncFile extends Object implements ReadStream<Buffer>, WriteStream<Buffer>
Represents a file on the file-system which can be read from, or written to asynchronously.This class also implements
NOTE: This class has been automatically generated from theReadStream
andWriteStream
. This allows the data to be piped to and from other streams, e.g. anHttpClientRequest
instance, using thePipe
classoriginal
non Mutiny-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<AsyncFile>
__TYPE_ARG
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description io.smallrye.mutiny.Uni<Void>
close()
Close the file.Void
closeAndAwait()
Blocking variant ofclose()
.void
closeAndForget()
Variant ofclose()
that ignores the result of the operation.AsyncFile
drainHandler(Runnable handler)
io.smallrye.mutiny.Uni<Void>
end()
Same asWriteStream.end()
but with anhandler
called when the operation completesio.smallrye.mutiny.Uni<Void>
end(Buffer data)
Same as but with anhandler
called when the operation completesVoid
endAndAwait()
Blocking variant ofWriteStream.end()
.Void
endAndAwait(Buffer data)
Blocking variant ofio.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer)
.void
endAndForget()
Variant ofWriteStream.end()
that ignores the result of the operation.void
endAndForget(Buffer data)
Variant ofio.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer)
that ignores the result of the operation.AsyncFile
endHandler(Runnable endHandler)
boolean
equals(Object o)
AsyncFile
exceptionHandler(Consumer<Throwable> handler)
AsyncFile
fetch(long amount)
io.smallrye.mutiny.Uni<Void>
flush()
Same asflush()
but the handler will be called when the flush is complete or if an error occursVoid
flushAndAwait()
Blocking variant offlush()
.AsyncFile
flushAndForget()
Variant offlush()
that ignores the result of the operation.io.vertx.core.file.AsyncFile
getDelegate()
long
getReadLength()
long
getWritePos()
AsyncFile
handler(Consumer<Buffer> handler)
int
hashCode()
io.smallrye.mutiny.Uni<AsyncFileLock>
lock()
Likelock()
but thehandler
will be called when the operation is complete or if an error occurs.io.smallrye.mutiny.Uni<AsyncFileLock>
lock(long position, long size, boolean shared)
Likelock()
but thehandler
will be called when the operation is complete or if an error occurs.AsyncFileLock
lockAndAwait()
Blocking variant oflock()
.AsyncFileLock
lockAndAwait(long position, long size, boolean shared)
Blocking variant oflock(long,long,boolean)
.void
lockAndForget()
Variant oflock()
that ignores the result of the operation.void
lockAndForget(long position, long size, boolean shared)
Variant oflock(long,long,boolean)
that ignores the result of the operation.static AsyncFile
newInstance(io.vertx.core.file.AsyncFile arg)
AsyncFile
pause()
Pipe<Buffer>
pipe()
io.smallrye.mutiny.Uni<Void>
pipeTo(WriteStream<Buffer> dst)
Pipe thisReadStream
to theWriteStream
.Void
pipeToAndAwait(WriteStream<Buffer> dst)
Blocking variant ofReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream)
.void
pipeToAndForget(WriteStream<Buffer> dst)
Variant ofReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream)
that ignores the result of the operation.io.smallrye.mutiny.Uni<Buffer>
read(Buffer buffer, int offset, long position, int length)
Readslength
bytes of data from the file at positionposition
in the file, asynchronously.Buffer
readAndAwait(Buffer buffer, int offset, long position, int length)
Blocking variant ofread(io.vertx.mutiny.core.buffer.Buffer,int,long,int)
.AsyncFile
readAndForget(Buffer buffer, int offset, long position, int length)
Variant ofread(io.vertx.mutiny.core.buffer.Buffer,int,long,int)
that ignores the result of the operation.AsyncFile
resume()
AsyncFile
setReadBufferSize(int readBufferSize)
AsyncFile
setReadLength(long readLength)
AsyncFile
setReadPos(long readPos)
AsyncFile
setWritePos(long writePos)
AsyncFile
setWriteQueueMaxSize(int maxSize)
io.smallrye.mutiny.Uni<Long>
size()
Likesize()
but thehandler
will be called when the operation is complete or if an error occurs.Long
sizeAndAwait()
Blocking variant ofsize()
.void
sizeAndForget()
Variant ofsize()
that ignores the result of the operation.long
sizeBlocking()
Iterable<Buffer>
toBlockingIterable()
Stream<Buffer>
toBlockingStream()
io.smallrye.mutiny.Multi<Buffer>
toMulti()
String
toString()
WriteStreamSubscriber<Buffer>
toSubscriber()
AsyncFileLock
tryLock()
AsyncFileLock
tryLock(long position, long size, boolean shared)
io.smallrye.mutiny.Uni<Void>
write(Buffer data)
Same as but with anhandler
called when the operation completesio.smallrye.mutiny.Uni<Void>
write(Buffer buffer, long position)
Write aBuffer
to the file at positionposition
in the file, asynchronously.Void
writeAndAwait(Buffer data)
Blocking variant ofio.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer)
.Void
writeAndAwait(Buffer buffer, long position)
Blocking variant ofwrite(io.vertx.mutiny.core.buffer.Buffer,long)
.void
writeAndForget(Buffer data)
Variant ofio.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer)
that ignores the result of the operation.void
writeAndForget(Buffer buffer, long position)
Variant ofwrite(io.vertx.mutiny.core.buffer.Buffer,long)
that ignores the result of the operation.boolean
writeQueueFull()
-
-
-
Constructor Detail
-
AsyncFile
public AsyncFile(io.vertx.core.file.AsyncFile delegate)
-
AsyncFile
public AsyncFile(Object delegate)
-
-
Method Detail
-
getDelegate
public io.vertx.core.file.AsyncFile getDelegate()
- Specified by:
getDelegate
in interfaceReadStream<Buffer>
- Specified by:
getDelegate
in interfaceStreamBase
- Specified by:
getDelegate
in interfaceWriteStream<Buffer>
-
toSubscriber
@CheckReturnValue public WriteStreamSubscriber<Buffer> toSubscriber()
-
write
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> write(Buffer data)
Same as but with anhandler
called when the operation completesUnlike 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 interfaceWriteStream<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 ofio.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 interfaceWriteStream<Buffer>
- Parameters:
data
-- Returns:
- the Void instance produced by the operation.
-
writeAndForget
public void writeAndForget(Buffer data)
Variant ofio.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 fromio.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 interfaceWriteStream<Buffer>
- Parameters:
data
-
-
end
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> end()
Same asWriteStream.end()
but with anhandler
called when the operation completesUnlike 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 interfaceWriteStream<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 ofWriteStream.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 interfaceWriteStream<Buffer>
- Returns:
- the Void instance produced by the operation.
-
endAndForget
public void endAndForget()
Variant ofWriteStream.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 fromWriteStream.end()
but you don't need to compose it with other operations.- Specified by:
endAndForget
in interfaceWriteStream<Buffer>
-
end
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> end(Buffer data)
Same as but with anhandler
called when the operation completesUnlike 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 interfaceWriteStream<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 ofio.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 interfaceWriteStream<Buffer>
- Parameters:
data
-- Returns:
- the Void instance produced by the operation.
-
endAndForget
public void endAndForget(Buffer data)
Variant ofio.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 fromio.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 interfaceWriteStream<Buffer>
- Parameters:
data
-
-
writeQueueFull
public boolean writeQueueFull()
- Specified by:
writeQueueFull
in interfaceWriteStream<Buffer>
- Returns:
true
if write queue is full
-
pipe
public Pipe<Buffer> pipe()
- Specified by:
pipe
in interfaceReadStream<Buffer>
- Returns:
- a pipe
-
pipeTo
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<Buffer> dst)
Pipe thisReadStream
to theWriteStream
.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 interfaceReadStream<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 ofReadStream.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 interfaceReadStream<Buffer>
- Parameters:
dst
- the destination write stream- Returns:
- the Void instance produced by the operation.
-
pipeToAndForget
public void pipeToAndForget(WriteStream<Buffer> dst)
Variant ofReadStream.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 fromReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream)
but you don't need to compose it with other operations.- Specified by:
pipeToAndForget
in interfaceReadStream<Buffer>
- Parameters:
dst
- the destination write stream
-
handler
public AsyncFile handler(Consumer<Buffer> handler)
- Specified by:
handler
in interfaceReadStream<Buffer>
- Returns:
-
pause
public AsyncFile pause()
- Specified by:
pause
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
resume
public AsyncFile resume()
- Specified by:
resume
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
public AsyncFile endHandler(Runnable endHandler)
- Specified by:
endHandler
in interfaceReadStream<Buffer>
- Returns:
-
setWriteQueueMaxSize
public AsyncFile setWriteQueueMaxSize(int maxSize)
- Specified by:
setWriteQueueMaxSize
in interfaceWriteStream<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 interfaceWriteStream<Buffer>
- Parameters:
handler
- the handler- Returns:
-
exceptionHandler
public AsyncFile exceptionHandler(Consumer<Throwable> handler)
- Specified by:
exceptionHandler
in interfaceReadStream<Buffer>
- Specified by:
exceptionHandler
in interfaceStreamBase
- Specified by:
exceptionHandler
in interfaceWriteStream<Buffer>
- Parameters:
handler
- the exception handler- Returns:
-
fetch
public AsyncFile fetch(long amount)
- Specified by:
fetch
in interfaceReadStream<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 ofclose()
.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()
-
write
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> write(Buffer buffer, long position)
Write aBuffer
to the file at positionposition
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 writeposition
- 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 ofwrite(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 writeposition
- 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 ofwrite(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 fromwrite(io.vertx.mutiny.core.buffer.Buffer,long)
but you don't need to compose it with other operations.- Parameters:
buffer
- the buffer to writeposition
- 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)
Readslength
bytes of data from the file at positionposition
in the file, asynchronously.The read data will be written into the specified
Buffer buffer
at positionoffset
.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 intooffset
- the offset into the buffer where the data will be readposition
- the position in the file where to start readinglength
- 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 ofread(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 intooffset
- the offset into the buffer where the data will be readposition
- the position in the file where to start readinglength
- 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 ofread(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 fromread(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 intooffset
- the offset into the buffer where the data will be readposition
- the position in the file where to start readinglength
- 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 asflush()
but the handler will be called when the flush is complete or if an error occursUnlike 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 offlush()
.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 offlush()
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 fromflush()
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()
Likesize()
but thehandler
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 ofsize()
.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()
-
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 startssize
- the size of the regionshared
- 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()
Likelock()
but thehandler
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 oflock()
.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()
-
lock
@CheckReturnValue public io.smallrye.mutiny.Uni<AsyncFileLock> lock(long position, long size, boolean shared)
Likelock()
but thehandler
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 oflock(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 oflock(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 fromlock(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 interfaceReadStream<Buffer>
-
newInstance
public static AsyncFile newInstance(io.vertx.core.file.AsyncFile arg)
-
-