Class AsyncFile
- All Implemented Interfaces:
MutinyDelegate
,ReadStream<Buffer>
,StreamBase
,WriteStream<Buffer>
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
original
non Mutiny-ified interface using Vert.x codegen.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.smallrye.mutiny.Uni<Void>
close()
Close the file.Blocking variant ofclose()
.void
Variant ofclose()
that ignores the result of the operation.drainHandler
(Runnable handler) io.smallrye.mutiny.Uni<Void>
end()
Same asWriteStream.end()
but with anhandler
called when the operation completesio.smallrye.mutiny.Uni<Void>
Same as but with anhandler
called when the operation completesBlocking variant ofWriteStream.end()
.endAndAwait
(Buffer data) Blocking variant ofio.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer)
.void
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.endHandler
(Runnable endHandler) boolean
exceptionHandler
(Consumer<Throwable> handler) 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 occursBlocking variant offlush()
.Variant offlush()
that ignores the result of the operation.io.vertx.core.file.AsyncFile
long
long
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.Blocking variant oflock()
.lockAndAwait
(long position, long size, boolean shared) Blocking variant oflock(long,long,boolean)
.void
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) pause()
pipe()
io.smallrye.mutiny.Uni<Void>
pipeTo
(WriteStream<Buffer> dst) Pipe thisReadStream
to theWriteStream
.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>
Readslength
bytes of data from the file at positionposition
in the file, asynchronously.readAndAwait
(Buffer buffer, int offset, long position, int length) Blocking variant ofread(io.vertx.mutiny.core.buffer.Buffer,int,long,int)
.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.resume()
setReadBufferSize
(int readBufferSize) setReadLength
(long readLength) setReadPos
(long readPos) setWritePos
(long writePos) 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.Blocking variant ofsize()
.void
Variant ofsize()
that ignores the result of the operation.long
io.smallrye.mutiny.Multi<Buffer>
toMulti()
toString()
tryLock()
tryLock
(long position, long size, boolean shared) io.smallrye.mutiny.Uni<Void>
Same as but with anhandler
called when the operation completesio.smallrye.mutiny.Uni<Void>
Write aBuffer
to the file at positionposition
in the file, asynchronously.writeAndAwait
(Buffer data) Blocking variant ofio.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer)
.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
-
Field Details
-
__TYPE_ARG
-
-
Constructor Details
-
AsyncFile
public AsyncFile(io.vertx.core.file.AsyncFile delegate) -
AsyncFile
-
-
Method Details
-
getDelegate
public io.vertx.core.file.AsyncFile getDelegate()- Specified by:
getDelegate
in interfaceMutinyDelegate
- Specified by:
getDelegate
in interfaceReadStream<Buffer>
- Specified by:
getDelegate
in interfaceStreamBase
- Specified by:
getDelegate
in interfaceWriteStream<Buffer>
- Returns:
- the delegate used by this Mutiny object of generated type
-
toString
-
equals
-
hashCode
public int hashCode() -
toSubscriber
-
write
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
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
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
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
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
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
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
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
- Specified by:
pipe
in interfaceReadStream<Buffer>
- Returns:
- a pipe
-
pipeTo
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
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
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
- Specified by:
handler
in interfaceReadStream<Buffer>
- Returns:
-
pause
- Specified by:
pause
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
resume
- Specified by:
resume
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
- Specified by:
endHandler
in interfaceReadStream<Buffer>
- Returns:
-
setWriteQueueMaxSize
- 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
- Specified by:
drainHandler
in interfaceWriteStream<Buffer>
- Parameters:
handler
- the handler- Returns:
-
exceptionHandler
- Specified by:
exceptionHandler
in interfaceReadStream<Buffer>
- Specified by:
exceptionHandler
in interfaceStreamBase
- Specified by:
exceptionHandler
in interfaceWriteStream<Buffer>
- Parameters:
handler
- the exception handler- Returns:
-
fetch
- Specified by:
fetch
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
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
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
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
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
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
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
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
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
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
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
- Parameters:
readPos
- the position in the file- Returns:
- a reference to this, so the API can be used fluently
-
setReadLength
- 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
- 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
- Parameters:
readBufferSize
- the buffer size- Returns:
- a reference to this, so the API can be used fluently
-
sizeBlocking
public long sizeBlocking()- Returns:
-
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
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
- Returns:
- the lock if it can be acquired immediately, otherwise
null
-
tryLock
- 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
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
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
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
- Specified by:
toMulti
in interfaceReadStream<Buffer>
-
toBlockingIterable
-
toBlockingStream
-
newInstance
-