Example usage for java.nio.channels CompletionHandler interface-usage

List of usage examples for java.nio.channels CompletionHandler interface-usage

Introduction

In this page you can find the example usage for java.nio.channels CompletionHandler interface-usage.

Usage

From source file Main.java

class ConnectionHandler implements CompletionHandler<AsynchronousSocketChannel, Attachment> {
    @Override
    public void completed(AsynchronousSocketChannel client, Attachment attach) {
        try {
            SocketAddress clientAddr = client.getRemoteAddress();
            System.out.format("Accepted a  connection from  %s%n", clientAddr);

From source file Main.java

class ReadWriteHandler implements CompletionHandler<Integer, Attachment> {
    @Override
    public void completed(Integer result, Attachment attach) {
        if (attach.isRead) {
            attach.buffer.flip();
            Charset cs = Charset.forName("UTF-8");

From source file Main.java

class WriteHandler implements CompletionHandler<Integer, Attachment> {
    @Override
    public void completed(Integer result, Attachment attach) {
        System.out.format("%s bytes written  to  %s%n", result, attach.path.toAbsolutePath());
        try {
            attach.asyncChannel.close();