java.nio.channels


1. Creating a ServerSocketChannel with SocketOptions:

ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
SocketOptions options = SocketOptions.getDefault();
options.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverSocketChannel.configureBlocking(false);
serverSocketChannel.setOption(options);

2. Setting TCP No Delay:

SocketChannel socketChannel = SocketChannel.open();
socketChannel.configureBlocking(false);
socketChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);

3. Reading from a SocketChannel with ByteBuffer:

ByteBuffer buffer = ByteBuffer.allocate(1024);
int bytesRead = socketChannel.read(buffer);
if (bytesRead > 0) {
    buffer.flip();
    byte[] data = new byte[bytesRead];
    buffer.get(data);
    // Process data
}

4. Writing to a SocketChannel with ByteBuffer:

5. Creating a FileChannel for a File:

6. Reading from a FileChannel with ByteBuffer:

7. Writing to a FileChannel with ByteBuffer:

8. Creating a DatagramChannel:

9. Sending a UDP Message with DatagramChannel:

10. Receiving a UDP Message with DatagramChannel:

11. Creating a Pipe:

12. Using a PipeSourceChannel to Write to a Pipe:

13. Using PipeSinkChannel to Read from a Pipe:

14. Creating a Selector:

15. Registering a SocketChannel with a Selector:

16. Registering a FileChannel with a Selector:

17. Checking for Ready Keys:

18. Accepting a Connection:

19. Reading Data from a SocketChannel (non-blocking):

20. Writing Data to a SocketChannel (non-blocking):

21. Closing a SocketChannel (asynchronous):

22. Using a MappedByteBuffer:

23. Creating a FileLock:

24. Using a TransferTo operation:

25. Using a Gather operation:

26. Using a Scatter operation:

27. Managing Channel Groups:

28. Handling Asynchronous Operations:

29. Using Path APIs:

30. Using FileSystems:

31. Using AsynchronousFileChannel:

32. Using Selectors with AsynchronousFileChannel:

33. Using WatchService:

34. Using Standard Channels:

35. Using Non-Blocking I/O with CompletionHandler:

36. Using Scattering Reads and Gathering Writes:

37. Using Interruptible Channels:

38. Implementing a Simple Server Using Selectors:

39. Implementing a Simple Client Using Selectors:

40. Using Non-Blocking I/O with Futures:

41. Using Non-Blocking I/O with Callables and Futures:

42. Using a Buffer Overflow Handler:

43. Using a Channel Pipelines:

44. Using a Channel Handlers:

45. Using a Channel Event Trigger:

46. Using a Channel Filters:

47. Using a ChannelPromise:

48. Using a ChannelGroupFuture:

49. Using a ChannelPool:

50. Using a ChannelOption: