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

no subtypes hierarchy

Initializer
AsyncFile(AsyncFile unknown)
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
closeshared default void close()

Close the file. The actual close happens asynchronously.

closeshared default void close(Anything(Throwable?) handler)

Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.

Parameters:
  • handler

    the handler

drainHandlershared actual default AsyncFile drainHandler(Anything()? handler)

Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pump for an example of this being used.

The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to maxSize / 2.

endshared actual default void end()

Close the file, see close.

endshared actual default void end(Buffer t)

Same as end but writes some data to the stream before ending.

endHandlershared actual default AsyncFile endHandler(Anything()? endHandler)

Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.

exceptionHandlershared actual default AsyncFile exceptionHandler(Anything(Throwable)? handler)

Set an exception handler.

flushshared default AsyncFile flush()

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.

flushshared default AsyncFile flush(Anything(Throwable?) handler)

Same as flush but the handler will be called when the flush is complete or if an error occurs

handlershared actual default AsyncFile handler(Anything(Buffer)? handler)

Set a data handler. As data is read, the handler will be called with the data.

pauseshared actual default AsyncFile pause()

Pause the ReadSupport. While it's paused, no data will be sent to the dataHandler

readshared default AsyncFile read(Buffer buffer, Integer offset, Integer position, Integer length, Anything(Throwable|Buffer) handler)

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.

Parameters:
  • buffer

    the buffer to read into

  • offset

    the offset into the buffer where the data will be read

  • position

    the position in the file where to start reading

  • length

    the number of bytes to read

  • handler

    the handler to call when the write is complete

resumeshared actual default AsyncFile resume()

Resume reading. If the ReadSupport has been paused, reading will recommence on it.

setReadBufferSizeshared default AsyncFile setReadBufferSize(Integer readBufferSize)

Sets 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.

Parameters:
  • readBufferSize

    the buffer size

setReadPosshared default AsyncFile setReadPos(Integer readPos)

Sets the position from which data will be read from when using the file as a ReadStream.

Parameters:
  • readPos

    the position in the file

setWritePosshared default AsyncFile setWritePos(Integer writePos)

Sets the position from which data will be written when using the file as a WriteStream.

Parameters:
  • writePos

    the position in the file

setWriteQueueMaxSizeshared actual default AsyncFile setWriteQueueMaxSize(Integer maxSize)

Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize items in the write queue. This is used as an indicator by classes such as Pump to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, the number of Message for a MessageProducer, etc…

writeshared actual default AsyncFile write(Buffer data)
writeshared default AsyncFile write(Buffer buffer, Integer position, Anything(Throwable?) handler)

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.

Parameters:
  • buffer

    the buffer to write

  • position

    the position in the file to write it at

  • handler

    the handler to call when the write is complete

writeQueueFullshared actual default Boolean writeQueueFull()

This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize

Inherited Methods
Methods inherited from: Object
equals
Methods inherited from: ReadStream<T>
Methods inherited from: StreamBase
Methods inherited from: WriteStream<T>