Package de.esoco.coroutine.step.nio
Class FileWrite
- java.lang.Object
-
- org.obrel.core.RelatedObject
-
- de.esoco.coroutine.CoroutineStep<I,O>
-
- de.esoco.coroutine.step.nio.AsynchronousChannelStep<java.nio.ByteBuffer,java.nio.ByteBuffer>
-
- de.esoco.coroutine.step.nio.AsynchronousFileStep
-
- de.esoco.coroutine.step.nio.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 aAsynchronousFileChannel.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.esoco.coroutine.step.nio.AsynchronousChannelStep
AsynchronousChannelStep.ChannelCallback<V,C extends java.nio.channels.AsynchronousChannel>, AsynchronousChannelStep.ChannelOperation<C extends java.nio.channels.AsynchronousChannel>
-
-
Field Summary
-
Fields inherited from class de.esoco.coroutine.step.nio.AsynchronousFileStep
FILE_CHANNEL, FILE_POSITION
-
Fields inherited from class de.esoco.coroutine.step.nio.AsynchronousChannelStep
CHANNEL_GROUP
-
-
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 booleanperformAsyncOperation(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 voidperformBlockingOperation(java.nio.channels.AsynchronousFileChannel channel, java.nio.ByteBuffer data)Must be implemented for the blocking execution of a step.static FileWritewriteTo(java.lang.String fileName, java.nio.file.OpenOption... extraOptions)InvokeswriteTo(Function)with a function that opens a file channel with the given file name and options.static FileWritewriteTo(java.util.function.Function<Continuation<?>,java.nio.channels.AsynchronousFileChannel> getFileChannel)Suspends until all data from the inputByteBufferhas been written to a file.The buffer must be initialized for sending, i.e. if necessary a call toBuffer.flip()must have been performed.-
Methods inherited from class de.esoco.coroutine.step.nio.AsynchronousFileStep
execute, getFileChannel, getFileChannelFactory, openFileChannel, runAsync
-
Methods inherited from class de.esoco.coroutine.step.nio.AsynchronousChannelStep
getChannelGroup
-
Methods inherited from class de.esoco.coroutine.CoroutineStep
runBlocking, terminateCoroutine, toString
-
Methods inherited from class org.obrel.core.RelatedObject
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
-
-
-
-
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 inputByteBufferhas been written to a file.The buffer must be initialized for sending, i.e. if necessary a call toBuffer.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)
InvokeswriteTo(Function)with a function that opens a file channel with the given file name and options. The optionStandardOpenOption.WRITEwill always be used and should therefore not occur in the extra options.- Parameters:
fileName- The name of the file to read fromextraOptions- Additional options to use besidesStandardOpenOption.WRITE- Returns:
- A new step instance
-
performAsyncOperation
protected boolean performAsyncOperation(int bytesWritten, java.nio.channels.AsynchronousFileChannel channel, java.nio.ByteBuffer data, AsynchronousChannelStep.ChannelCallback<java.lang.Integer,java.nio.channels.AsynchronousFileChannel> callback)Description copied from class:AsynchronousFileStepImplementation of the ChannelOperation functional interface method signature.
-
performBlockingOperation
protected void performBlockingOperation(java.nio.channels.AsynchronousFileChannel channel, java.nio.ByteBuffer data) throws java.lang.InterruptedException, java.util.concurrent.ExecutionExceptionDescription copied from class:AsynchronousFileStepMust be implemented for the blocking execution of a step. It receives anAsynchronousFileChannelwhich must be accessed through the blocking API (likeFuture.get()).- Specified by:
performBlockingOperationin classAsynchronousFileStep- Parameters:
channel- The channel to perform the operation ondata- The byte buffer for the operation data- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionException
-
-