One day a class of--nio buffer

Source: Internet
Author: User

Java.nio---Defines the subclasses associated with Buffer and its data type. The Bytebuffer of the classes used in Java.nio.channels for IO operations is very important.

java.nio.channels----Defines a series of Channel interfaces for processing IO and the implementation of these interfaces on file systems and network communications. The Selector class also provides a way to do non-blocking IO operations. This package can be said to be the core of the NIO API.

The JAVA.NIO.CHANNELS.SPI----defines an abstract class that can be used to implement the channel and selector APIs.

Java.nio.charset----defines classes that handle character encoding and decoding.

The JAVA.NIO.CHARSET.SPI----defines an abstract class 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, and in practice we typically only deal with 3 additional packages.

Java.nio

  This package mainly defines the Buffer and its subclasses. Buffer defines a container interface for linear storage of primitive type data. For primitive type other than Boolean, there is a corresponding Buffer subclass, and Bytebuffer is one of the most important subclasses of the class.

A buffer is a linear, finite sequence of elements of a specific primitive type. Aside from its content, the essential properties of a buffer is its capacity, limit, and position.

Buffer is a linear and limited storage area, with three important attributes for buffer (in fact there is another called Mark)

A Buffer ' s capacityis The number of elements it contains. The capacity of a buffer is never negative and never changes.

Indicates the capacity size of buffer, non-negative, immutable.

A Buffer's limit is the index of the first element, the should not being read or written. A buffer ' s limit is never negative and is never greater than its capacity.

Represents the first subscript that cannot read an element, for example, 3 elements are stored (subscript 0,1,2) at this time limit=3.

A Buffer ' s position is the index of the next element to be read or written. A Buffer ' s position is never negative and is never greater than its limit.

Represents the first element that is currently available.

[note] there is one subclass of this class for each Non-boolean primitive type. The subtype of the class is not of type Boolean.

The get and put methods are defined in all subclasses.

A Buffer's Mark is the "index to which its position would be reset when the" reset method is invoked.  The mark isn't always defined, if it is defined it's never negative and is never greater than the position.  If The mark was defined then it was discarded when the position or the limit was adjusted to a value smaller than the mark. If The mark is not a defined then invoking the Reset method causes a invalidmarkexception to be thrown.

A temporary storage location subscript. calling Mark () sets mark to the value of the current position , and subsequent calls to reset () will set the Position property to the value of Mark. Mark's value is always less than or equal to position, and if the value of position is set smaller than mark, the current mark value is discarded.

clearing, flipping, and rewinding

clear: makes a buffer ready for a new sequence of channel-read or relative put Operations:it sets the Lim It to the capacity and the position to zero. limit = capacity, Position = 0

makes a buffer ready for a new sequence of channel-write or relative get operations:it sets the limit to the Current position and then sets the position to zero.

A class--nio of one day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.