import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import java.nio.ByteBuffer;
import java.net.InetSocketAddress;
import java.io.IOException;
import java.lang.Integer;
import java.lang.StringBuilder;

public class AioServer{
  public static void main(String[] args) throws Exception{
    new AioServer().init();
    System.out.println("Server has started successfully...");
    Thread.sleep(Integer.MAX_VALUE);
  }

  public void init() throws Exception{
    final AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open().
      bind(new InetSocketAddress(8081));
    listener.accept(null, new CompletionHandler<AsynchronousSocketChannel, Void>(){
      public void completed(AsynchronousSocketChannel channel, Void att){
        listener.accept(null, this);
        handle(channel);
      }

      public void failed(Throwable throwable, Void att){
        System.err.println(throwable);
      }
    });
  }

  private void handle(AsynchronousSocketChannel channel){
    try{
      StringBuilder sb = new StringBuilder();
      sb.append("HTTP/1.1 200 OK\r\n");
      sb.append("Content-Type: text/html; charset=UTF-8\r\n\r\n");
      sb.append("<doctype !html><html><head><title>Hello</title>");
      sb.append("<style>body { background-color: #111 }");
      sb.append("h1 { font-size:4cm; text-align: center; color: black;");
      sb.append("text-shadow: 0 0 2mm red}</style></head>");
      sb.append("<body><h1>Hello AIO !</h1></body></html>\r\n");
      channel.write(ByteBuffer.wrap(sb.toString().getBytes()));
      channel.shutdownOutput();
      channel.close();
    }catch(IOException ex){
      System.err.println(ex);
    }
  }
}

@@ -321,16 +321,18 @@
 Server%7B%0A
+  
   public
@@ -378,24 +378,28 @@
  Exception%7B%0A
+    
     new AioS
@@ -410,24 +410,28 @@
 r().init();%0A
+    
     System.o
@@ -484,16 +484,20 @@
 %22);%0A    
+ 
+   
 Thread.s
@@ -521,23 +521,27 @@
 VALUE);%0A
+  
   %7D%0A%0A  
+ 
+ 
 public v
@@ -565,24 +565,28 @@
  Exception%7B%0A
+    
     final As
@@ -665,23 +665,16 @@
 .open().
-%0A      
 bind(new
@@ -696,24 +696,28 @@
 ess(8081));%0A
+    
     listener
@@ -788,16 +788,22 @@
 oid%3E()%7B%0A
+      
       pu
@@ -868,32 +868,40 @@
 d att)%7B%0A        
+     
+   
 listener.accept(
@@ -913,16 +913,24 @@
  this);%0A
+        
         
@@ -956,17 +956,29 @@
     
-%7D%0A%0A
+      %7D%0A%0A     
       
+ 
 publ
@@ -1016,32 +1016,40 @@
 ble, Void att)%7B%0A
+        
         System.e
@@ -1081,25 +1081,39 @@
     
+  
-%7D%0A
+    %7D%0A  
     
+  
 %7D);%0A  
+ 
+ 
 %7D%0A%0A  
+ 
+ 
 priv
@@ -1164,16 +1164,20 @@
 annel)%7B%0A
+    
     try%7B
@@ -1177,16 +1177,22 @@
    try%7B%0A
+      
       St
@@ -1225,24 +1225,30 @@
 gBuilder();%0A
+      
       sb.app
@@ -1273,32 +1273,38 @@
 OK%5Cr%5Cn%22);%0A      
+     
+ 
 sb.append(%22Conte
@@ -1346,32 +1346,38 @@
 %5Cn%5Cr%5Cn%22);%0A      
+     
+ 
 sb.append(%22%3Cdoct
@@ -1420,32 +1420,38 @@
 title%3E%22);%0A      
+    
+  
 sb.append(%22%3Cstyl
@@ -1483,24 +1483,30 @@
 : #111 %7D%22);%0A
+      
       sb.app
@@ -1565,32 +1565,38 @@
 black;%22);%0A      
+   
+   
 sb.append(%22text-
@@ -1636,24 +1636,30 @@
 d%3E%22);%0A      
+   
+   
 sb.append(%22%3C
@@ -1703,32 +1703,38 @@
 l%3E%5Cr%5Cn%22);%0A      
+  
+    
 channel.write(By
@@ -1771,24 +1771,30 @@
 tBytes()));%0A
+      
       channe
@@ -1815,24 +1815,30 @@
 ut();%0A      
+ 
+     
 channel.clos
@@ -1838,24 +1838,28 @@
 el.close();%0A
+    
     %7Dcatch(I
@@ -1876,24 +1876,30 @@
  ex)%7B%0A      
+  
+    
 System.err.p
@@ -1914,16 +1914,22 @@
 x);%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

Format source code