@groovy.transform.CompileStatic class AsyncFile extends java.lang.Object
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 pumped to and from other streams, e.g. an HttpClientRequest instance, using the Pump class
Constructor and description |
---|
AsyncFile
(java.lang.Object delegate) |
Type | Name and description |
---|---|
void |
close() Close the file. |
void |
close(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler) Close the file. |
AsyncFile |
drainHandler(io.vertx.core.Handler<java.lang.Void> handler) |
void |
end(Buffer t) Same as AsyncFile.end but writes some data to the stream before ending. |
void |
end() Close the file, see AsyncFile.close. |
AsyncFile |
endHandler(io.vertx.core.Handler<java.lang.Void> endHandler) |
AsyncFile |
exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler) |
AsyncFile |
flush() Flush any writes made to this file to underlying persistent storage. |
AsyncFile |
flush(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler) Same as AsyncFile.flush but the handler will be called when the flush is complete or if an error occurs |
java.lang.Object |
getDelegate() |
AsyncFile |
handler(io.vertx.core.Handler<Buffer> handler) |
AsyncFile |
pause() |
AsyncFile |
read(Buffer buffer, int offset, long position, int length, io.vertx.core.Handler<io.vertx.core.AsyncResult<Buffer>> handler) Reads length bytes of data from the file at position position in the file, asynchronously. |
AsyncFile |
resume() |
AsyncFile |
setReadBufferSize(int readBufferSize) Sets the buffer size that will be used to read the data from the file. |
AsyncFile |
setReadPos(long readPos) Sets the position from which data will be read from when using the file as a ReadStream. |
AsyncFile |
setWritePos(long writePos) Sets the position from which data will be written when using the file as a WriteStream. |
AsyncFile |
setWriteQueueMaxSize(int maxSize) |
AsyncFile |
write(Buffer data) |
AsyncFile |
write(Buffer buffer, long position, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler) Write a Buffer to the file at position position in the file, asynchronously. |
boolean |
writeQueueFull() This will return true if there are more bytes in the write queue than the value set using AsyncFile.setWriteQueueMaxSize |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Close the file. The actual close happens asynchronously.
Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.
handler
- the handlerSame as AsyncFile.end but writes some data to the stream before ending.
Close the file, see AsyncFile.close.
Flush any writes made to this file to underlying persistent storage.
If the file was opened with flush
set to true
then calling this method will have no effect.
The actual flush will happen asynchronously.
Same as AsyncFile.flush but the handler will be called when the flush is complete or if an error occurs
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.
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 readhandler
- the handler to call when the write is completeSets the buffer size that will be used to read the data from the file. Changing this value will impact how much the data will be read at a time from the file system.
readBufferSize
- the buffer sizeSets the position from which data will be read from when using the file as a ReadStream.
readPos
- the position in the fileSets the position from which data will be written when using the file as a WriteStream.
writePos
- the position in the file 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.
buffer
- the buffer to writeposition
- the position in the file to write it athandler
- the handler to call when the write is complete This will return true
if there are more bytes in the write queue than the value set using AsyncFile.setWriteQueueMaxSize