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 theReadStreamandWriteStream. This allows the data to be piped to and from other streams, e.g. anHttpClientRequestinstance, using thePipeclassoriginalnon 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.VoidcloseAndAwait()Blocking variant ofclose().voidcloseAndForget()Variant ofclose()that ignores the result of the operation.AsyncFiledrainHandler(Runnable handler)io.smallrye.mutiny.Uni<Void>end()Same asWriteStream.end()but with anhandlercalled when the operation completesio.smallrye.mutiny.Uni<Void>end(Buffer data)Same as but with anhandlercalled when the operation completesVoidendAndAwait()Blocking variant ofWriteStream.end().VoidendAndAwait(Buffer data)Blocking variant ofio.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer).voidendAndForget()Variant ofWriteStream.end()that ignores the result of the operation.voidendAndForget(Buffer data)Variant ofio.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer)that ignores the result of the operation.AsyncFileendHandler(Runnable endHandler)booleanequals(Object o)AsyncFileexceptionHandler(Consumer<Throwable> handler)AsyncFilefetch(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 occursVoidflushAndAwait()Blocking variant offlush().AsyncFileflushAndForget()Variant offlush()that ignores the result of the operation.io.vertx.core.file.AsyncFilegetDelegate()longgetReadLength()longgetWritePos()AsyncFilehandler(Consumer<Buffer> handler)inthashCode()io.smallrye.mutiny.Uni<AsyncFileLock>lock()Likelock()but thehandlerwill 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 thehandlerwill be called when the operation is complete or if an error occurs.AsyncFileLocklockAndAwait()Blocking variant oflock().AsyncFileLocklockAndAwait(long position, long size, boolean shared)Blocking variant oflock(long,long,boolean).voidlockAndForget()Variant oflock()that ignores the result of the operation.voidlockAndForget(long position, long size, boolean shared)Variant oflock(long,long,boolean)that ignores the result of the operation.static AsyncFilenewInstance(io.vertx.core.file.AsyncFile arg)AsyncFilepause()Pipe<Buffer>pipe()io.smallrye.mutiny.Uni<Void>pipeTo(WriteStream<Buffer> dst)Pipe thisReadStreamto theWriteStream.VoidpipeToAndAwait(WriteStream<Buffer> dst)Blocking variant ofReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream).voidpipeToAndForget(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)Readslengthbytes of data from the file at positionpositionin the file, asynchronously.BufferreadAndAwait(Buffer buffer, int offset, long position, int length)Blocking variant ofread(io.vertx.mutiny.core.buffer.Buffer,int,long,int).AsyncFilereadAndForget(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.AsyncFileresume()AsyncFilesetReadBufferSize(int readBufferSize)AsyncFilesetReadLength(long readLength)AsyncFilesetReadPos(long readPos)AsyncFilesetWritePos(long writePos)AsyncFilesetWriteQueueMaxSize(int maxSize)io.smallrye.mutiny.Uni<Long>size()Likesize()but thehandlerwill be called when the operation is complete or if an error occurs.LongsizeAndAwait()Blocking variant ofsize().voidsizeAndForget()Variant ofsize()that ignores the result of the operation.longsizeBlocking()Iterable<Buffer>toBlockingIterable()Stream<Buffer>toBlockingStream()io.smallrye.mutiny.Multi<Buffer>toMulti()StringtoString()WriteStreamSubscriber<Buffer>toSubscriber()AsyncFileLocktryLock()AsyncFileLocktryLock(long position, long size, boolean shared)io.smallrye.mutiny.Uni<Void>write(Buffer data)Same as but with anhandlercalled when the operation completesio.smallrye.mutiny.Uni<Void>write(Buffer buffer, long position)Write aBufferto the file at positionpositionin the file, asynchronously.VoidwriteAndAwait(Buffer data)Blocking variant ofio.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer).VoidwriteAndAwait(Buffer buffer, long position)Blocking variant ofwrite(io.vertx.mutiny.core.buffer.Buffer,long).voidwriteAndForget(Buffer data)Variant ofio.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer)that ignores the result of the operation.voidwriteAndForget(Buffer buffer, long position)Variant ofwrite(io.vertx.mutiny.core.buffer.Buffer,long)that ignores the result of the operation.booleanwriteQueueFull()
-
-
-
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:
getDelegatein interfaceReadStream<Buffer>- Specified by:
getDelegatein interfaceStreamBase- Specified by:
getDelegatein interfaceWriteStream<Buffer>
-
toSubscriber
@CheckReturnValue public WriteStreamSubscriber<Buffer> toSubscriber()
-
write
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> write(Buffer data)
Same as but with anhandlercalled 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:
writein interfaceWriteStream<Buffer>- Parameters:
data-- Returns:
- the
unifiring 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:
writeAndAwaitin 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:
writeAndForgetin interfaceWriteStream<Buffer>- Parameters:
data-
-
end
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> end()
Same asWriteStream.end()but with anhandlercalled 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:
endin interfaceWriteStream<Buffer>- Returns:
- the
unifiring 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:
endAndAwaitin 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:
endAndForgetin interfaceWriteStream<Buffer>
-
end
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> end(Buffer data)
Same as but with anhandlercalled 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:
endin interfaceWriteStream<Buffer>- Parameters:
data-- Returns:
- the
unifiring 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:
endAndAwaitin 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:
endAndForgetin interfaceWriteStream<Buffer>- Parameters:
data-
-
writeQueueFull
public boolean writeQueueFull()
- Specified by:
writeQueueFullin interfaceWriteStream<Buffer>- Returns:
trueif write queue is full
-
pipe
public Pipe<Buffer> pipe()
- Specified by:
pipein interfaceReadStream<Buffer>- Returns:
- a pipe
-
pipeTo
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<Buffer> dst)
Pipe thisReadStreamto 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
handlerwill 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:
pipeToin interfaceReadStream<Buffer>- Parameters:
dst- the destination write stream- Returns:
- the
unifiring 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:
pipeToAndAwaitin 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:
pipeToAndForgetin interfaceReadStream<Buffer>- Parameters:
dst- the destination write stream
-
handler
public AsyncFile handler(Consumer<Buffer> handler)
- Specified by:
handlerin interfaceReadStream<Buffer>- Returns:
-
pause
public AsyncFile pause()
- Specified by:
pausein interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
resume
public AsyncFile resume()
- Specified by:
resumein interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
public AsyncFile endHandler(Runnable endHandler)
- Specified by:
endHandlerin interfaceReadStream<Buffer>- Returns:
-
setWriteQueueMaxSize
public AsyncFile setWriteQueueMaxSize(int maxSize)
- Specified by:
setWriteQueueMaxSizein 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:
drainHandlerin interfaceWriteStream<Buffer>- Parameters:
handler- the handler- Returns:
-
exceptionHandler
public AsyncFile exceptionHandler(Consumer<Throwable> handler)
- Specified by:
exceptionHandlerin interfaceReadStream<Buffer>- Specified by:
exceptionHandlerin interfaceStreamBase- Specified by:
exceptionHandlerin interfaceWriteStream<Buffer>- Parameters:
handler- the exception handler- Returns:
-
fetch
public AsyncFile fetch(long amount)
- Specified by:
fetchin 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
unifiring 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 aBufferto the file at positionpositionin the file, asynchronously.If
positionlies 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
unifiring 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)
Readslengthbytes of data from the file at positionpositionin the file, asynchronously.The read data will be written into the specified
Buffer bufferat 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
unifiring 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
unifiring 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 thehandlerwill 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
unifiring 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 thehandlerwill 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
unifiring 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 thehandlerwill 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
unifiring 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:
toMultiin interfaceReadStream<Buffer>
-
newInstance
public static AsyncFile newInstance(io.vertx.core.file.AsyncFile arg)
-
-