Scatter/Gather or Vectored I/O22 Mar 2025 | 3 min read In Java NIO the channel provides an important capability known as scatter/gather or vectored I/O. It is a simple yet powerful technique through which the bytes can be written from a set of buffers to a stream using a single write() function and bytes can be read from a stream into a set of buffers using a single read() function. Java NIO has inbuilt scatter/gather support. It can be used in reading from channels and writing to channels. Scattering ReadsThe 'scattering read' is used for reading the data from a single channel into multiple buffers. Let's see the illustration of the Scatter principle: ![]() Let's see the code example that performs a scattering read operation: Gathering WritesThe 'gathering write' is used for writing the data from a multiple buffers into a single channel. Let's see the simple illustration of the Gather principle: ![]() Let's see the code example that performs a gathering write operation: Basic Scatter/Gather ExampleLet's see the simple example of two buffers. The first buffer holds a random number and second buffer holds the data we want to write using scatter/gather mechanism: Output: In above program, first buffer print the random output on a console and second buffer print the "Scattering and Gathering example shown in Tpointtech.com" on a console. It also replaces the content of testout.txt file with "Scattering and Gathering example shown in tpointtech.com". Next TopicData Transfer between Channels |
NIO Encode/Decode
Encode and Decode in Java NIO Using Java NIO API encode and decode operation can be perform from one Charset to another Charset. The two classes' CharsetEncoder and CharsetDecoder play an important role in encoding and decoding between the ByteBuffer and CharBuffer. The reactor keeps the track...
2 min read
NIO SocketChannel
Java The Java is used for connecting a channel with a TCP (Transmission Control Protocol) network socket. It is equivalent to Java Networking Sockets used in network programming. There are two methods available for creating a SocketChannel in Java NIO: It can be created when an incoming...
2 min read
NIO Pipe
Java A Java is used for establishing the one-way data connection between two threads. It has a sink channel and source channel. The data is writing to the sink channel and this data can then be read from a source channel. In Java NIO the...
3 min read
NIO Package
Java The NIO classes are contained in a package called java.nio package. It is important to understand that the NIO subsystem does not replace the stream based I/O classes available in java.io package, and good working knowledge of stream-based I/O in java.io is helpful for understanding...
2 min read
NIO Selector
Java In Java NIO the selector is a multiplexor of selectable channels, which is used as a special type of channel that can be put into non-blocking mode. It can examine one or more NIO Channel's and determines which channel is ready for communication i.e....
7 min read
NIO CharSet
Java NIO Charset The concept of charset is introduced in JDK 1.4 using the package java.nio.charset.Charset. It plays an important role in encoding and decoding between the given charset and UNICODE. The name of charset must follow certain rules. It must begin with the number or letter....
1 min read
NIO Channels FileLock
FileLock in Java NIO Channels FileLock locks or tries to lock the given part of the file. It belongs to the package java.nio.channels and this feature is available in java from JDK 1.4. FileLock is used for locking the files in either shared mode or non-shared mode....
3 min read
NIO Components
Java In Java NIO reading and writing are the fundamental process of I/O. Reading from channel: We can create a buffer and then ask a channel to read the data. Writing from channel: We can create a buffer, fill it with data and ask a...
2 min read
NIO Channels
Java In Java NIO, the channel is a medium used to transports the data efficiently between the entity and byte buffers. It reads the data from an entity and places it inside buffer blocks for consumption. Channels act as gateway provided by java NIO to access...
3 min read
NIO vs. IO
Java IO vs. NIO Let's see the table showing the main differences between Java IO and NIO: IO NIO ...
4 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India

