Class/Object

monix.nio.file

AsyncFileChannel

Related Docs: object AsyncFileChannel | package file

Permalink

abstract class AsyncFileChannel extends AutoCloseable

An asynchronous channel for reading, writing, and manipulating a file.

On the JVM this is a wrapper around java.nio.channels.AsynchronousFileChannel (class available since Java 7 for doing async I/O on files).

Example:
  1. val out = AsyncFileChannel(File.createTempFile, StandardOpenOption.CREATE)
    val bytes = ByteBuffer.wrap("Hello world!".getBytes("UTF-8"))
    val future = out.write(bytes, 0)
    future.onComplete {
      case Success(nr) =>
        println("Bytes written: %d".format(nr))
      case Failure(exc) =>
        println(s"ERROR: " + exc.getMessage)
    }
Linear Supertypes
AutoCloseable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AsyncFileChannel
  2. AutoCloseable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new AsyncFileChannel()

    Permalink

Abstract Value Members

  1. abstract def close(): Unit

    Permalink
    Definition Classes
    AutoCloseable
    Annotations
    @throws( classOf[java.lang.Exception] )
  2. abstract def flush(writeMetaData: Boolean, cb: Callback[Throwable, Unit]): Unit

    Permalink

    Forces any updates to this channel's file to be written to the storage device that contains it.

    Forces any updates to this channel's file to be written to the storage device that contains it.

    Invoking this method might trigger an fsync or fdatasync operation, which transfers all modified in-core data of the file to the disk device, so that all changed information can be retrieved even after the system crashed or was rebooted. If the writeMetaData is set to true, then this would be the equivalent of an fsync command, or fdatasync if set to false.

    This method is only guaranteed to force changes that were made to this channel's file via the methods defined in this class.

    writeMetaData

    if true then this method is required to force changes to both the file's content and metadata to be written to storage; otherwise, it need only force content changes to be written

    cb

    is a callback to be called when the asynchronous operation succeeds, or for signaling errors

  3. abstract def isOpen: Boolean

    Permalink

    Returns true if this channel is open, or false otherwise.

  4. abstract def read(dst: ByteBuffer, position: Long, cb: Callback[Throwable, Int]): Unit

    Permalink

    Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

    Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

    dst

    is the buffer holding the bytes read on completion

    position

    is the position in the opened channel from where to read

    cb

    is the callback to be called with the result, once this asynchronous operation is complete . For this method it signals the number of bytes read or -1 if the given position is greater than or equal to the file's size at the time the read is attempted.

  5. abstract def size(cb: Callback[Throwable, Long]): Unit

    Permalink

    Returns the current size of this channel's file, measured in bytes.

  6. abstract def write(src: ByteBuffer, position: Long, cb: Callback[Throwable, Int]): Unit

    Permalink

    Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

    Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

    If the given position is greater than the file's size, at the time that the write is attempted, then the file will be grown to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.

    src

    is the buffer holding the sequence of bytes to write

    position

    is the position in file where to write, starts from 0, must be positive

    cb

    is the callback to be called with the result, once this asynchronous operation is complete . For this method it signals the number of bytes that were written

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. def flush(writeMetaData: Boolean): Future[Unit]

    Permalink

    Forces any updates to this channel's file to be written to the storage device that contains it.

    Forces any updates to this channel's file to be written to the storage device that contains it.

    Invoking this method might trigger an fsync or fdatasync operation, which transfers all modified in-core data of the file to the disk device, so that all changed information can be retrieved even after the system crashed or was rebooted. If the writeMetaData is set to true, then this would be the equivalent of an fsync command, or fdatasync if set to false.

    This method is only guaranteed to force changes that were made to this channel's file via the methods defined in this class.

    writeMetaData

    if true then this method is required to force changes to both the file's content and metadata to be written to storage; otherwise, it need only force content changes to be written

  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. def read(dst: ByteBuffer, position: Long): Future[Int]

    Permalink

    Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

    Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.

    dst

    is the buffer holding the bytes read on completion

    position

    is the position in the opened channel from where to read

    returns

    the number of bytes read or -1 if the given position is greater than or equal to the file's size at the time the read is attempted.

  17. def size: Future[Long]

    Permalink

    Returns the current size of this channel's file, measured in bytes.

  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  19. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. def write(src: ByteBuffer, position: Long): Future[Int]

    Permalink

    Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

    Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

    If the given position is greater than the file's size, at the time that the write is attempted, then the file will be grown to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.

    src

    is the buffer holding the sequence of bytes to write

    position

    is the position in file where to write, starts from 0, must be positive

    returns

    the number of bytes that were written

Inherited from AutoCloseable

Inherited from AnyRef

Inherited from Any

Ungrouped