Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does Java NIO API have?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Xiaobian to share with you what Java NIO API, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of gains after reading this article, let's go to understand it together!

The NIO API is mainly concentrated in java.nio and its subpackages:

java.nio

Buffer and its data type-dependent subclasses are defined. ByteBuffer, which is used by the classes in java.nio.channels for IO operations, plays an important role.

java.nio.channels

A series of Channel interfaces for IO processing and their implementation on file system and network communication are defined. The Selector class also provides a way to perform asynchronous IO operations. This package is arguably the heart of the NIO API.

java.nio.channels.spi

Defines abstract classes that can be used to implement the channel and selector APIs.

java.nio.charset

Defines classes that handle character encoding and decoding.

java.nio.charset.spi

Defines abstract classes that can be used to implement the charset API.

java.nio.channels.spi and java.nio.charset.spi are mainly used to extend the existing NIO API. In practice, we usually only deal with the other three packages. These three packages are described below.

Package java.nio

This package mainly defines Buffer and its subclasses. Buffer defines a container interface for linearly storing primitive type data. For primitive types other than boolean, there is a Buffer subclass, ByteBuffer being the most important.

The following UML class diagram describes the class relationships in java.nio:

Buffer

Defines a container interface that can store primitive type data linearly. Buffer mainly contains functions independent of type (byte, char…). Note that Buffer and its subclasses are not thread-safe.

Each Buffer has the following properties:

capacity

How much data can this Buffer hold? Capacity is usually specified when the buffer is created.

limit

No read or write operation on Buffer can go beyond this index. When writing data to a buffer, limit is generally equal to capacity; when reading data, limit represents the length of valid data in the buffer.

position

The current subscript of the read/write operation. When a read/write operation is performed using the relative position of the buffer, the read/write is performed from this index, and the buffer updates the index value after the operation is completed.

mark

A temporary storage index. Calling mark() sets mark to the current value of position, and later calls to reset() set the position property to the value of mark. The value of mark is always less than or equal to the value of position. If you set the value of position to be less than mark, the current value of mark will be discarded.

These attributes always satisfy the following conditions:

0

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report