CharBuffer: wrap(CharSequence csq) : CharBuffer « java.nio « Java by API






CharBuffer: wrap(CharSequence csq)

  
import java.nio.CharBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;

public class MainClass {
  public static void main(String[] args) throws Exception{

    CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();

    ServerSocketChannel server = ServerSocketChannel.open();
    server.socket().bind(new java.net.InetSocketAddress(8000));

    for (;;) { // This server runs forever
      SocketChannel client = server.accept();
      String response = new java.util.Date().toString() + "\r\n";
      client.write(encoder.encode(CharBuffer.wrap(response)));
      client.close();
    }
  }
}

           
         
    
  








Related examples in the same category

1.CharBuffer: allocate(int capacity)
2.CharBuffer: array()
3.CharBuffer: arrayOffset()
4.CharBuffer: capacity()
5.CharBuffer: flip()
6.CharBuffer: get()
7.CharBuffer: hasArray()
8.CharBuffer: hasRemaining()
9.CharBuffer: limit()
10.CharBuffer: limit(int newLimit)
11.CharBuffer: position()
12.CharBuffer: put(char c)
13.CharBuffer: put(String str)
14.CharBuffer: slice()
15.CharBuffer: subSequence(int start, int end)
16.CharBuffer: wrap(char[] array, int offset, int length)