public class FileRead extends AsynchronousFileStep
AsynchronousFileChannel
.AsynchronousChannelStep.ChannelCallback<V,C extends java.nio.channels.AsynchronousChannel>, AsynchronousChannelStep.ChannelOperation<C extends java.nio.channels.AsynchronousChannel>
FILE_CHANNEL, FILE_POSITION
CHANNEL_GROUP
Constructor and Description |
---|
FileRead(java.util.function.Function<Continuation<?>,java.nio.channels.AsynchronousFileChannel> fGetFileChannel,
java.util.function.BiPredicate<java.lang.Integer,java.nio.ByteBuffer> pCheckFinished)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
performAsyncOperation(int nBytesRead,
java.nio.channels.AsynchronousFileChannel rChannel,
java.nio.ByteBuffer rData,
AsynchronousChannelStep.ChannelCallback<java.lang.Integer,java.nio.channels.AsynchronousFileChannel> rCallback)
Implementation of the ChannelOperation functional interface method
signature.
|
protected void |
performBlockingOperation(java.nio.channels.AsynchronousFileChannel aChannel,
java.nio.ByteBuffer rData)
Must be implemented for the blocking execution of a step.
|
static AsynchronousFileStep |
readFrom(java.util.function.Function<Continuation<?>,java.nio.channels.AsynchronousFileChannel> fGetFileChannel)
Suspends until a file has been read completely.
|
static AsynchronousFileStep |
readFrom(java.lang.String sFileName,
java.nio.file.OpenOption... rExtraOptions)
Invokes
readFrom(Function) with a function that opens a file
channel with the given file name and options. |
AsynchronousFileStep |
until(java.util.function.BiPredicate<java.lang.Integer,java.nio.ByteBuffer> pCheckFinished)
Returns a new read step instance the suspends until data has been read
from a file and a certain condition on that data is met or an
end-of-stream signal is received.
|
execute, getFileChannel, getFileChannelFactory, openFileChannel, runAsync
getChannelGroup
fail, runBlocking, terminateCoroutine, toString
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public FileRead(java.util.function.Function<Continuation<?>,java.nio.channels.AsynchronousFileChannel> fGetFileChannel, java.util.function.BiPredicate<java.lang.Integer,java.nio.ByteBuffer> pCheckFinished)
fGetFileChannel
- A function that provides the file channel from the
current continuationpCheckFinished
- A predicate that checks whether the operation is
complete by evaluating the byte buffer after
readingpublic static AsynchronousFileStep readFrom(java.util.function.Function<Continuation<?>,java.nio.channels.AsynchronousFileChannel> fGetFileChannel)
ByteBuffer
of the step. If the capacity of the
buffer is reached before the EOF signal is received the coroutine will be
terminated with a CoroutineException
. To stop reading when a
certain condition is met a derived step can be created with #until(Predicate)
.
After the data has been fully received Buffer.flip()
will
be invoked on the buffer so that it can be used directly for subsequent
reading from it.
fGetFileChannel
- A function that provides the file channel from
the current continuationpublic static AsynchronousFileStep readFrom(java.lang.String sFileName, java.nio.file.OpenOption... rExtraOptions)
readFrom(Function)
with a function that opens a file
channel with the given file name and options. The option StandardOpenOption.READ
will always be used and should therefore not
occur in the extra options.sFileName
- The name of the file to read fromrExtraOptions
- Additional options to use besides StandardOpenOption.READ
public AsynchronousFileStep until(java.util.function.BiPredicate<java.lang.Integer,java.nio.ByteBuffer> pCheckFinished)
pCheckFinished
- A predicate that checks whether the data has been
read completelyprotected boolean performAsyncOperation(int nBytesRead, java.nio.channels.AsynchronousFileChannel rChannel, java.nio.ByteBuffer rData, AsynchronousChannelStep.ChannelCallback<java.lang.Integer,java.nio.channels.AsynchronousFileChannel> rCallback) throws java.io.IOException
performAsyncOperation
in class AsynchronousFileStep
java.io.IOException
AsynchronousChannelStep.ChannelOperation.execute(int,java.nio.channels.AsynchronousChannel,
ByteBuffer, AsynchronousChannelStep.ChannelCallback)
protected void performBlockingOperation(java.nio.channels.AsynchronousFileChannel aChannel, java.nio.ByteBuffer rData) throws java.lang.Exception
AsynchronousFileChannel
which must be accessed through the
blocking API (like Future.get()
).performBlockingOperation
in class AsynchronousFileStep
aChannel
- The channel to perform the operation onrData
- The byte buffer for the operation datajava.lang.Exception
- Any kind of exception may be thrown