NIO编程之buffer源码学习

进入buffer.java这个java文件

 * 

There is one subclass of this class for each non-boolean primitive type.

对于不同的数据类型都有相应的子类,除了boolean类型

 * 

Transferring data

* 传输数据 *

Each subclass of this class defines two categories of get and * put operations:

* 每一个子类都定义了两种操作 get和out *
* *

Relative operations read or write one or more elements starting * at the current position and then increment the position by the number of * elements transferred. 相对操作 从当前位置 读或者写一个或者多个元素 position你增加相应的数量 If the requested transfer exceeds the limit then a * relative get operation throws a {@link BufferUnderflowException} * and a relative put operation throws a {@link * BufferOverflowException}; in either case, no data is transferred.

* 如果get操作超过了limit的限制,会抛出BufferUnderflowException 如果put操作闯过了limit的限制,会抛出BufferOverflowException *

Absolute operations take an explicit element index and do not * affect the position. Absolute get and put operations throw * an {@link IndexOutOfBoundsException} if the index argument exceeds the * limit.

* 绝对的操作(直接操作索引,不会影响position),绝对的get和put如果超过了 IndexOutOfBoundsException *
* *

Data may also, of course, be transferred in to or out of a buffer by the * I/O operations of an appropriate channel, which are always relative to the * current position.

Marking and resetting

* *

A buffer's mark is the index to which its position will be reset * when the {@link #reset reset} method is invoked. 当调用这个方法的时候,会回到mark标记的位置 The mark is not always * defined, but when it is defined it is never negative and is never greater * than the position. mark不经常使用,但是在使用的时候不可能为负数,并且不可能比position的值要大 If the mark is defined then it is discarded when the * position or the limit is adjusted to a value smaller than the mark. mark会被废弃,当position和limit被修改成比mark还要小的值 If the * mark is not defined then invoking the {@link #reset reset} method causes an * {@link InvalidMarkException} to be thrown. mark和reset要成对的定义,否则会抛出异常

Invariants

* *

The following invariant holds for the mark, position, limit, and * capacity values: * *

* 0 <= * mark <= * position <= * limit <= * capacity *
* 大小关系 0 <= mark <= position <= limit <=capacity *

A newly-created buffer always has a position of zero and a mark that is * undefined. 新创建的buffer是0而且mark未被定义 The initial limit may be zero, or it may be some other value * that depends upon the type of the buffer and the manner in which it is * constructed. limit初始化时有可能为0,也有可能是其他值,取决于他的结构 Each element of a newly-allocated buffer is initialized * to zero. 新定义的buffer的元素位置都为空

你可能感兴趣的:(NIO编程之buffer源码学习)