src/java.base/share/classes/java/nio/Buffer.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8076112 Sdiff src/java.base/share/classes/java/nio

src/java.base/share/classes/java/nio/Buffer.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.nio;
  27 
  28 import java.util.Spliterator;

  29 
  30 /**
  31  * A container for data of a specific primitive type.
  32  *
  33  * <p> A buffer is a linear, finite sequence of elements of a specific
  34  * primitive type.  Aside from its content, the essential properties of a
  35  * buffer are its capacity, limit, and position: </p>
  36  *
  37  * <blockquote>
  38  *
  39  *   <p> A buffer's <i>capacity</i> is the number of elements it contains.  The
  40  *   capacity of a buffer is never negative and never changes.  </p>
  41  *
  42  *   <p> A buffer's <i>limit</i> is the index of the first element that should
  43  *   not be read or written.  A buffer's limit is never negative and is never
  44  *   greater than its capacity.  </p>
  45  *
  46  *   <p> A buffer's <i>position</i> is the index of the next element to be
  47  *   read or written.  A buffer's position is never negative and is never
  48  *   greater than its limit.  </p>


 518      */
 519     final int nextPutIndex() {                          // package-private
 520         if (position >= limit)
 521             throw new BufferOverflowException();
 522         return position++;
 523     }
 524 
 525     final int nextPutIndex(int nb) {                    // package-private
 526         if (limit - position < nb)
 527             throw new BufferOverflowException();
 528         int p = position;
 529         position += nb;
 530         return p;
 531     }
 532 
 533     /**
 534      * Checks the given index against the limit, throwing an {@link
 535      * IndexOutOfBoundsException} if it is not smaller than the limit
 536      * or is smaller than zero.
 537      */

 538     final int checkIndex(int i) {                       // package-private
 539         if ((i < 0) || (i >= limit))
 540             throw new IndexOutOfBoundsException();
 541         return i;
 542     }
 543 
 544     final int checkIndex(int i, int nb) {               // package-private
 545         if ((i < 0) || (nb > limit - i))
 546             throw new IndexOutOfBoundsException();
 547         return i;
 548     }
 549 
 550     final int markValue() {                             // package-private
 551         return mark;
 552     }
 553 
 554     final void truncate() {                             // package-private
 555         mark = -1;
 556         position = 0;
 557         limit = 0;


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.nio;
  27 
  28 import java.util.Spliterator;
  29 import jdk.internal.HotSpotIntrinsicCandidate;
  30 
  31 /**
  32  * A container for data of a specific primitive type.
  33  *
  34  * <p> A buffer is a linear, finite sequence of elements of a specific
  35  * primitive type.  Aside from its content, the essential properties of a
  36  * buffer are its capacity, limit, and position: </p>
  37  *
  38  * <blockquote>
  39  *
  40  *   <p> A buffer's <i>capacity</i> is the number of elements it contains.  The
  41  *   capacity of a buffer is never negative and never changes.  </p>
  42  *
  43  *   <p> A buffer's <i>limit</i> is the index of the first element that should
  44  *   not be read or written.  A buffer's limit is never negative and is never
  45  *   greater than its capacity.  </p>
  46  *
  47  *   <p> A buffer's <i>position</i> is the index of the next element to be
  48  *   read or written.  A buffer's position is never negative and is never
  49  *   greater than its limit.  </p>


 519      */
 520     final int nextPutIndex() {                          // package-private
 521         if (position >= limit)
 522             throw new BufferOverflowException();
 523         return position++;
 524     }
 525 
 526     final int nextPutIndex(int nb) {                    // package-private
 527         if (limit - position < nb)
 528             throw new BufferOverflowException();
 529         int p = position;
 530         position += nb;
 531         return p;
 532     }
 533 
 534     /**
 535      * Checks the given index against the limit, throwing an {@link
 536      * IndexOutOfBoundsException} if it is not smaller than the limit
 537      * or is smaller than zero.
 538      */
 539     @HotSpotIntrinsicCandidate
 540     final int checkIndex(int i) {                       // package-private
 541         if ((i < 0) || (i >= limit))
 542             throw new IndexOutOfBoundsException();
 543         return i;
 544     }
 545 
 546     final int checkIndex(int i, int nb) {               // package-private
 547         if ((i < 0) || (nb > limit - i))
 548             throw new IndexOutOfBoundsException();
 549         return i;
 550     }
 551 
 552     final int markValue() {                             // package-private
 553         return mark;
 554     }
 555 
 556     final void truncate() {                             // package-private
 557         mark = -1;
 558         position = 0;
 559         limit = 0;
src/java.base/share/classes/java/nio/Buffer.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File