com.fireflysource.common.io.InputChannel Maven / Gradle / Ivy
The newest version!
package com.fireflysource.common.io;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousChannel;
import java.util.concurrent.CompletableFuture;
public interface InputChannel extends AsynchronousChannel, AsyncCloseable {
int END_OF_STREAM_FLAG = -1;
/**
* Read the content asynchronously.
*
* @param byteBuffer The buffer into which bytes are to be transferred.
* @return The number of bytes read. If return -1, it presents the end of the content.
*/
CompletableFuture read(ByteBuffer byteBuffer);
/**
* Return the end of stream flag future wrap.
*
* @return The end of stream flag.
*/
default CompletableFuture endStream() {
CompletableFuture future = new CompletableFuture<>();
future.complete(END_OF_STREAM_FLAG);
return future;
}
}