In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are buffers and channels in the NIO library". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what buffers and channels are in the NIO library.
What is a buffer zone?
A Buffer is an object that contains data to be written to or just read out. The addition of the Buffer object to NIO reflects an important difference between the new library and the original one. In stream-oriented iCompO, you write data directly or read data directly into a Stream object.
In the NIO library, all data is processed with buffers. When reading data, it reads directly into the buffer. When the data is written, it is written to the buffer. Whenever you access data in NIO, you put it in a buffer.
The buffer is essentially an array. It is usually a byte array, but other kinds of arrays can also be used. But a buffer is more than an array. Buffers provide structured access to data and track the read / write process of the system.
Buffer type
The most commonly used buffer type is ByteBuffer. A ByteBuffer can perform get/set operations (that is, byte acquisition and setting) on its underlying byte array.
ByteBuffer is not the only buffer type in NIO. In fact, there is a buffer type for every basic Java type:
ByteBufferCharBufferShortBufferIntBufferLongBufferFloatBufferDoubleBuffer every Buffer class is an instance of the Buffer interface. Except for ByteBuffer, every Buffer class has exactly the same operation, except that they deal with different data types. Because most standard iCandle O operations use ByteBuffer, it has all shared buffer operations as well as some unique operations.
Now you can take a moment to run UseFloatBuffer.java, which contains an example of an application for typed buffers.
What is a passageway
Channel is an object through which you can read and write data. Compare NIO with the original Ibank O, and the channel is like a stream.
As mentioned earlier, all data is processed through the Buffer object. You never write bytes directly to the channel; instead, you write data to a buffer that contains one or more bytes. Similarly, instead of reading a byte directly from the channel, you read the data from the channel into the buffer and get the byte from the buffer.
Channel Typ
The difference between a channel and a stream is that the channel is bidirectional. The stream only moves in one direction (a stream must be a subclass of InputStream or OutputStream), while the channel can be used for reading, writing, or both.
Because they are bi-directional, channels can better reflect the reality of the underlying operating system than streams. Especially in the UNIX model, the underlying operating system channels are bidirectional.
At this point, I believe you have a deeper understanding of "what are buffers and channels in the NIO library". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.