NIO编程之buffer源码学习

2019-02-26  本文已影响0人  柴崎越

进入buffer.java这个java文件

 * <p> There is one subclass of this class for each non-boolean primitive type.

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

 * <h2> Transferring data </h2>
 * 传输数据
 * <p> Each subclass of this class defines two categories of <i>get</i> and
 * <i>put</i> operations: </p>
 * 每一个子类都定义了两种操作 get和out
 * <blockquote>
 *   
 *   <p> <i>Relative</i> 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 <i>get</i> operation throws a {@link BufferUnderflowException}
 *   and a relative <i>put</i> operation throws a {@link
 *   BufferOverflowException}; in either case, no data is transferred.  </p>
 *   如果get操作超过了limit的限制,会抛出BufferUnderflowException
     如果put操作闯过了limit的限制,会抛出BufferOverflowException



 *   <p> <i>Absolute</i> operations take an explicit element index and do not
 *   affect the position.  Absolute <i>get</i> and <i>put</i> operations throw
 *   an {@link IndexOutOfBoundsException} if the index argument exceeds the
 *   limit.  </p>
 *   绝对的操作(直接操作索引,不会影响position),绝对的get和put如果超过了   IndexOutOfBoundsException       
 * </blockquote>
 *
 * <p> 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.
     
<h2> Marking and resetting </h2>
 *
 * <p> A buffer's <i>mark</i> 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要成对的定义,否则会抛出异常
<h2> Invariants </h2>
 *
 * <p> The following invariant holds for the mark, position, limit, and
 * capacity values:
 *
 * <blockquote>
 *     <tt>0</tt> <tt>&lt;=</tt>
 *     <i>mark</i> <tt>&lt;=</tt>
 *     <i>position</i> <tt>&lt;=</tt>
 *     <i>limit</i> <tt>&lt;=</tt>
 *     <i>capacity</i>
 * </blockquote>
 *   大小关系 0 <= mark <= position <= limit <=capacity
 * <p> 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的元素位置都为空
   
上一篇 下一篇

猜你喜欢

热点阅读