Home » Core Java » nio » channels

channels

java.nio.channels.spi.SelectorProvider Example

SelectorProvider is an abstract class defined in the java.nio.channels.spi package. This is a central service-provider class for selectors and selectable channels defined in the java.nio.channels API. A selector provider is a concrete subclass of this class that has a zero-argument constructor and implements the abstract factory methods of this class that return open channels and selector objects. A Java virtual ...

Read More »

java.nio.channels.Selector Example

This example shows the basic usage of Selector. This is an abstract class defined in the java.nio.channels package. Selector is a multiplexor of SelectableChannel objects. NOTE: From the thefreedictionary.com a data-multiplexer is defined as a multiplexer that permits two or more data sources to share a common transmission medium. Multiplexed, non-blocking I/O, which is much more scalable than thread-oriented, blocking ...

Read More »

java.nio.channels.ScatteringByteChannel Example

ScatteringByteChannel is an interface extends ReadableByteChannel and is defined in java.nio.channels package. This is a channel that can read bytes into a sequence of buffers. This interface defines two read methods. read(ByteBuffer [] dsts): Reads a sequence of bytes from this channel into the given buffers. read(ByteBuffer [] dsts, int offset, int length): Reads a sequence of bytes from this ...

Read More »

java.nio.channels.FileLock Example

This article introduces the FileLock class and its basic usage. This article examples show using file locks with FileChannels. The examples in this article are compiled and run in Windows OS environment. Note that Java SE 7 is required to run the code. 1. Introduction FileLock is a token representing a lock on a region of a file. This is ...

Read More »

java.nio.channels.AsynchronousChannelGroup Example

This article introduces the AsynchronousChannelGroup and its basic usage. This class is available since Java SE 7 as part of Java NIO 2 file API. This article’s example shows using this class with asynchronous channels. The example in this article is compiled and run in Windows OS environment. Note that Java SE 7 is required to run the code. 1. ...

Read More »

java.nio.channels.AsynchronousSocketChannel Example

This article introduces the AsynchronousSocketChannel and its basic usage. This class is available since Java SE 7 as part of Java NIO 2 file API. This article’s example shows the socket channel client sending messages to an AsynchronousServerSocketChannel server – in a client/server setup. The example in this article is compiled and run in Windows OS environment. Note that Java ...

Read More »

java.nio.channels.CompletionHandler Example

This article introduces the CompletionHandler and its basic usage. This interface is available since Java SE 7 as part of Java NIO 2 File API. This article’s example shows reading from a file using asynchronous file channel and using the completion handler to consume its result. The example in this article is compiled and run in Windows OS environment. Note ...

Read More »

java.nio.channels.AsynchronousFileChannel Example

This article introduces the AsynchronousFileChannel class and its basic usage. This class is available since the Java SE 7 as part of Java NIO 2 File API. This article shows reading from and writing to file using asynchronous file channels. The examples in this article are compiled and run in Windows OS environment. Note that Java SE 7 is required ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns