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 pumped to and from other streams, e.g. anHttpClientRequestinstance, using thePumpclassoriginalnon Mutiny-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<AsyncFile>__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description AsyncFile(io.vertx.core.file.AsyncFile delegate)
-
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(Consumer<Void> handler)io.smallrye.mutiny.Uni<Void>end()Close the file, seeclose().io.smallrye.mutiny.Uni<Void>end(Buffer data)Same as but with anhandlercalled when the operation completesVoidendAndAwait()Blocking variant ofend(io.vertx.mutiny.core.buffer.Buffer).VoidendAndAwait(Buffer data)Blocking variant ofio.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer).voidendAndForget()Variant ofend(io.vertx.mutiny.core.buffer.Buffer)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(Consumer<Void> 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()longgetWritePos()AsyncFilehandler(Consumer<Buffer> handler)inthashCode()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 ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream.) voidpipeToAndForget(WriteStream<Buffer> dst)Variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStreamthat 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).AsyncFileresume()AsyncFilesetReadBufferSize(int readBufferSize)AsyncFilesetReadLength(long readLength)AsyncFilesetReadPos(long readPos)AsyncFilesetWritePos(long writePos)AsyncFilesetWriteQueueMaxSize(int maxSize)Iterable<Buffer>toBlockingIterable()Stream<Buffer>toBlockingStream()io.smallrye.mutiny.Multi<Buffer>toMulti()StringtoString()WriteStreamSubscriber<Buffer>toSubscriber()io.smallrye.mutiny.Uni<Void>write(Buffer data)Same aswrite(io.vertx.mutiny.core.buffer.Buffer)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 ofwrite(io.vertx.mutiny.core.buffer.Buffer).VoidwriteAndAwait(Buffer buffer, long position)Blocking variant ofwrite(io.vertx.mutiny.core.buffer.Buffer,long).AsyncFilewriteAndForget(Buffer data)booleanwriteQueueFull()
-
-
-
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
public WriteStreamSubscriber<Buffer> toSubscriber()
-
end
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
-
writeQueueFull
public boolean writeQueueFull()
- Specified by:
writeQueueFullin interfaceWriteStream<Buffer>- Returns:
- true if write queue is full
-
pipe
public Pipe<Buffer> pipe()
- Specified by:
pipein interfaceReadStream<Buffer>- Returns:
- a pipe
-
pipeTo
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 ofio.vertx.mutiny.core.streams.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:
pipeToAndAwaitin interfaceReadStream<Buffer>- Parameters:
dst- the destination write stream- Returns:
- the Void instance produced by the operation
-
handler
public AsyncFile handler(Consumer<Buffer> handler)
- Specified by:
handlerin interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
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(Consumer<Void> endHandler)
- Specified by:
endHandlerin interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
write
public io.smallrye.mutiny.Uni<Void> write(Buffer data)
Same aswrite(io.vertx.mutiny.core.buffer.Buffer)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 ofwrite(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
-
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(Consumer<Void> handler)
- Specified by:
drainHandlerin interfaceWriteStream<Buffer>- Parameters:
handler- the handler- Returns:
- a reference to this, so the API can be used fluently
-
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:
- a reference to this, so the API can be used fluently
-
fetch
public AsyncFile fetch(long amount)
- Specified by:
fetchin interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
end
public io.smallrye.mutiny.Uni<Void> end()
Close the file, seeclose().Unlike 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 ofend(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>- Returns:
- the Void instance produced by the operation
-
close
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
-
write
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:
- a reference to this, so the API can be used fluently
-
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:
- a reference to this, so the API can be used fluently
-
read
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:
- a reference to this, so the API can be used fluently
-
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:
- a reference to this, so the API can be used fluently
-
flush
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
-
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
-
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
-
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.- Parameters:
data- the data to write
-
pipeToAndForget
public void pipeToAndForget(WriteStream<Buffer> dst)
Variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStreamthat ignores the result of the operation.) This method subscribes on the result of
io.vertx.mutiny.core.streams.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) io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStreambut you don't need to compose it with other operations.) - Parameters:
dst-
-
endAndForget
public void endAndForget()
Variant ofend(io.vertx.mutiny.core.buffer.Buffer)that ignores the result of the operation.This method subscribes on the result of
end(io.vertx.mutiny.core.buffer.Buffer), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromend(io.vertx.mutiny.core.buffer.Buffer)but you don't need to compose it with other operations.
-
closeAndForget
public void closeAndForget()
-
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:
- a reference to this, so the API can be used fluently
-
toMulti
public io.smallrye.mutiny.Multi<Buffer> toMulti()
- Specified by:
toMultiin interfaceReadStream<Buffer>
-
newInstance
public static AsyncFile newInstance(io.vertx.core.file.AsyncFile arg)
-
-