@@ -0,0 +1,2166 @@
+package com.github.booknara.nioexample;%0A%0Aimport java.io.IOException;%0Aimport java.nio.channels.SelectionKey;%0Aimport java.nio.channels.Selector;%0Aimport java.nio.channels.SocketChannel;%0Aimport java.util.Iterator;%0Aimport java.util.Set;%0A%0A/**%0A * Created by Daehee Han(@daniel_booknara) on 2/12/16.%0A * This example is an incomplete code.%0A */%0Apublic class SelectorExample %7B%0A    public static void main(String%5B%5D args) %7B%0A        Selector selector;%0A        // Define socket channel%0A//         SocketChannel channel = new SocketChannel();%0A//%0A//        try %7B%0A//            selector = Selector.open();%0A//            channel.configureBlocking(false);%0A//%0A//            SelectionKey selectionKey = channel.register(selector, SelectionKey.OP_READ);%0A//%0A//%0A//            while(true) %7B%0A//%0A//                // Return how many channels are ready to read%0A//                int readyChannels = selector.select();%0A//%0A//                if(readyChannels == 0)%0A//                    continue;%0A//%0A//%0A//                Set%3CSelectionKey%3E selectedKeys = selector.selectedKeys();%0A//%0A//                Iterator%3CSelectionKey%3E keyIterator = selectedKeys.iterator();%0A//%0A//                while(keyIterator.hasNext()) %7B%0A//%0A//                    SelectionKey key = keyIterator.next();%0A//%0A//                    if(key.isAcceptable()) %7B%0A//                        // a connection was accepted by a ServerSocketChannel.%0A//                        // ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel();%0A//                        // SocketChannel socketChannel = (SocketChannel) key.channel();%0A//%0A//                    %7D else if (key.isConnectable()) %7B%0A//                        // a connection was established with a remote server.%0A//%0A//                    %7D else if (key.isReadable()) %7B%0A//                        // a channel is ready for reading%0A//%0A//                    %7D else if (key.isWritable()) %7B%0A//                        // a channel is ready for writing%0A//                    %7D%0A//%0A//                    keyIterator.remove();%0A//                %7D%0A//            %7D%0A//%0A//        %7D catch (IOException e) %7B%0A//            System.out.println(e.getStackTrace());%0A//        %7D%0A%0A    %7D%0A%7D%0A

Add Selector example