I am working with the AsynchronousFileChannel for reading on the data. For reading the data, i found two read methods as follows:
//1.
Future<Integer> java.nio.channels.AsynchronousFileChannel.read(ByteBuffer dst, long position);
//2.
void java.nio.channels.AsynchronousFileChannel.read(ByteBuffer dst, long position, A attachment, CompletionHandler<Integer, ? super A> handler)
As the java documentation specified as below, there is no information about the CompletionHandler being used as the third parameter of the function:
Reads a sequence of bytes from this channel into the given buffer, starting at the given file position.
This method initiates the reading of a sequence of bytes from this channel into the given buffer, starting at the given file position. The result of the read is the number of bytes read or -1 if the given position is greater than or equal to the file's size at the time that the read is attempted.
This method works in the same manner as the AsynchronousByteChannel.read(ByteBuffer, Object, CompletionHandler) method, except that bytes are read starting at the given file position. If the given file position is greater than the file's size at the time that the read is attempted then no bytes are read.
Can anybody let me know about the third parameter, and any working example for CompletionHandler? Why do we need to CompletionHandler and what's its usage?