Class FileWrite

  • All Implemented Interfaces:
    de.esoco.lib.property.Fluent<CoroutineStep<java.nio.ByteBuffer,​java.nio.ByteBuffer>>, org.obrel.core.FluentRelatable<CoroutineStep<java.nio.ByteBuffer,​java.nio.ByteBuffer>>, org.obrel.core.Relatable

    public class FileWrite
    extends AsynchronousFileStep
    Implements asynchronous writing to a AsynchronousFileChannel.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileWrite​(java.util.function.Function<Continuation<?>,​java.nio.channels.AsynchronousFileChannel> getFileChannel)
      Creates a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean performAsyncOperation​(int bytesWritten, java.nio.channels.AsynchronousFileChannel channel, java.nio.ByteBuffer data, AsynchronousChannelStep.ChannelCallback<java.lang.Integer,​java.nio.channels.AsynchronousFileChannel> callback)
      Implementation of the ChannelOperation functional interface method signature.
      protected void performBlockingOperation​(java.nio.channels.AsynchronousFileChannel channel, java.nio.ByteBuffer data)
      Must be implemented for the blocking execution of a step.
      static FileWrite writeTo​(java.lang.String fileName, java.nio.file.OpenOption... extraOptions)
      Invokes writeTo(Function) with a function that opens a file channel with the given file name and options.
      static FileWrite writeTo​(java.util.function.Function<Continuation<?>,​java.nio.channels.AsynchronousFileChannel> getFileChannel)
      Suspends until all data from the input ByteBuffer has been written to a file.The buffer must be initialized for sending, i.e. if necessary a call to Buffer.flip() must have been performed.
      • Methods inherited from class org.obrel.core.RelatedObject

        deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface de.esoco.lib.property.Fluent

        _with
      • Methods inherited from interface org.obrel.core.FluentRelatable

        with, with, with
      • Methods inherited from interface org.obrel.core.Relatable

        deleteRelation, deleteRelation, deleteRelations, get, getAll, getOption, getRelation, getRelationCount, getRelations, getRelations, hasFlag, hasRelation, hasRelations, init, set, set, set, set, set, setOption, streamRelations, transform
    • Constructor Detail

      • FileWrite

        public FileWrite​(java.util.function.Function<Continuation<?>,​java.nio.channels.AsynchronousFileChannel> getFileChannel)
        Creates a new instance.
        Parameters:
        getFileChannel - A function that provides the file channel from the current continuation
    • Method Detail

      • writeTo

        public static FileWrite writeTo​(java.util.function.Function<Continuation<?>,​java.nio.channels.AsynchronousFileChannel> getFileChannel)
        Suspends until all data from the input ByteBuffer has been written to a file.The buffer must be initialized for sending, i.e. if necessary a call to Buffer.flip() must have been performed.

        After the data has been fully written ByteBuffer.clear() will be invoked on the buffer so that it can be used directly for subsequent writing to it.

        Parameters:
        getFileChannel - A function that provides the file channel from the current continuation
        Returns:
        A new step instance
      • writeTo

        public static FileWrite writeTo​(java.lang.String fileName,
                                        java.nio.file.OpenOption... extraOptions)
        Invokes writeTo(Function) with a function that opens a file channel with the given file name and options. The option StandardOpenOption.WRITE will always be used and should therefore not occur in the extra options.
        Parameters:
        fileName - The name of the file to read from
        extraOptions - Additional options to use besides StandardOpenOption.WRITE
        Returns:
        A new step instance
      • performBlockingOperation

        protected void performBlockingOperation​(java.nio.channels.AsynchronousFileChannel channel,
                                                java.nio.ByteBuffer data)
                                         throws java.lang.InterruptedException,
                                                java.util.concurrent.ExecutionException
        Description copied from class: AsynchronousFileStep
        Must be implemented for the blocking execution of a step. It receives an AsynchronousFileChannel which must be accessed through the blocking API (like Future.get()).
        Specified by:
        performBlockingOperation in class AsynchronousFileStep
        Parameters:
        channel - The channel to perform the operation on
        data - The byte buffer for the operation data
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException