< prev index next >

src/java.base/share/classes/java/nio/X-Buffer.java.template

Print this page


   1 /*
   2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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 #warn This file is preprocessed before being compiled
  27 
  28 package java.nio;
  29 
  30 #if[char]
  31 import java.io.IOException;
  32 #end[char]
  33 #if[streamableType]
  34 import java.util.Spliterator;
  35 import java.util.stream.StreamSupport;
  36 import java.util.stream.$Streamtype$Stream;
  37 #end[streamableType]
  38 

  39 import jdk.internal.util.ArraysSupport;
  40 
  41 /**
  42  * $A$ $type$ buffer.
  43  *
  44  * <p> This class defines {#if[byte]?six:four} categories of operations upon
  45  * $type$ buffers:
  46  *
  47  * <ul>
  48  *
  49  *   <li><p> Absolute and relative {@link #get() <i>get</i>} and
  50  *   {@link #put($type$) <i>put</i>} methods that read and write
  51  *   single $type$s; </p></li>
  52  *
  53  *   <li><p> Relative {@link #get($type$[]) <i>bulk get</i>}
  54  *   methods that transfer contiguous sequences of $type$s from this buffer
  55  *   into an array; {#if[!byte]?and}</p></li>
  56  *
  57  *   <li><p> Relative {@link #put($type$[]) <i>bulk put</i>}
  58  *   methods that transfer contiguous sequences of $type$s from $a$
  59  *   $type$ array{#if[char]?, a string,} or some other $type$
  60  *   buffer into this buffer;{#if[!byte]? and} </p></li>
  61  *
  62 #if[byte]
  63  *
  64  *   <li><p> Absolute and relative {@link #getChar() <i>get</i>}
  65  *   and {@link #putChar(char) <i>put</i>} methods that read and
  66  *   write values of other primitive types, translating them to and from
  67  *   sequences of bytes in a particular byte order; </p></li>
  68  *
  69  *   <li><p> Methods for creating <i><a href="#views">view buffers</a></i>,
  70  *   which allow a byte buffer to be viewed as a buffer containing values of
  71  *   some other primitive type; and </p></li>
  72  *
  73 #end[byte]
  74  *
  75  *   <li><p> A method for {@link #compact compacting}
  76  *   $a$ $type$ buffer.  </p></li>
  77  *


 417      *         The array that will back this buffer
 418      *
 419      * @return  The new $type$ buffer
 420      */
 421     public static $Type$Buffer wrap($type$[] array) {
 422         return wrap(array, 0, array.length);
 423     }
 424 
 425 #if[char]
 426 
 427     /**
 428      * Attempts to read characters into the specified character buffer.
 429      * The buffer is used as a repository of characters as-is: the only
 430      * changes made are the results of a put operation. No flipping or
 431      * rewinding of the buffer is performed.
 432      *
 433      * @param target the buffer to read characters into
 434      * @return The number of characters added to the buffer, or
 435      *         -1 if this source of characters is at its end
 436      * @throws IOException if an I/O error occurs
 437      * @throws NullPointerException if target is null
 438      * @throws ReadOnlyBufferException if target is a read only buffer
 439      * @since 1.5
 440      */
 441     public int read(CharBuffer target) throws IOException {
 442         // Determine the number of bytes n that can be transferred
 443         int targetRemaining = target.remaining();
 444         int remaining = remaining();
 445         if (remaining == 0)
 446             return -1;
 447         int n = Math.min(remaining, targetRemaining);
 448         int limit = limit();
 449         // Set source limit to prevent target overflow
 450         if (targetRemaining < remaining)
 451             limit(position() + n);
 452         try {
 453             if (n > 0)
 454                 target.put(this);
 455         } finally {
 456             limit(limit); // restore real limit
 457         }


 745      * <p> This method transfers $type$s from this buffer into the given
 746      * destination array.  An invocation of this method of the form
 747      * {@code src.get(a)} behaves in exactly the same way as the invocation
 748      *
 749      * <pre>
 750      *     src.get(a, 0, a.length) </pre>
 751      *
 752      * @param   dst
 753      *          The destination array
 754      *
 755      * @return  This buffer
 756      *
 757      * @throws  BufferUnderflowException
 758      *          If there are fewer than {@code length} $type$s
 759      *          remaining in this buffer
 760      */
 761     public $Type$Buffer get($type$[] dst) {
 762         return get(dst, 0, dst.length);
 763     }
 764 




















































































 765 
 766     // -- Bulk put operations --
 767 
 768     /**
 769      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
 770      *
 771      * <p> This method transfers the $type$s remaining in the given source
 772      * buffer into this buffer.  If there are more $type$s remaining in the
 773      * source buffer than in this buffer, that is, if
 774      * {@code src.remaining()}&nbsp;{@code >}&nbsp;{@code remaining()},
 775      * then no $type$s are transferred and a {@link
 776      * BufferOverflowException} is thrown.
 777      *
 778      * <p> Otherwise, this method copies
 779      * <i>n</i>&nbsp;=&nbsp;{@code src.remaining()} $type$s from the given
 780      * buffer into this buffer, starting at each buffer's current position.
 781      * The positions of both buffers are then incremented by <i>n</i>.
 782      *
 783      * <p> In other words, an invocation of this method of the form
 784      * {@code dst.put(src)} has exactly the same effect as the loop


 823      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
 824      *
 825      * <p> This method transfers $type$s into this buffer from the given
 826      * source array.  If there are more $type$s to be copied from the array
 827      * than remain in this buffer, that is, if
 828      * {@code length}&nbsp;{@code >}&nbsp;{@code remaining()}, then no
 829      * $type$s are transferred and a {@link BufferOverflowException} is
 830      * thrown.
 831      *
 832      * <p> Otherwise, this method copies {@code length} $type$s from the
 833      * given array into this buffer, starting at the given offset in the array
 834      * and at the current position of this buffer.  The position of this buffer
 835      * is then incremented by {@code length}.
 836      *
 837      * <p> In other words, an invocation of this method of the form
 838      * <code>dst.put(src,&nbsp;off,&nbsp;len)</code> has exactly the same effect as
 839      * the loop
 840      *
 841      * <pre>{@code
 842      *     for (int i = off; i < off + len; i++)
 843      *         dst.put(a[i]);
 844      * }</pre>
 845      *
 846      * except that it first checks that there is sufficient space in this
 847      * buffer and it is potentially much more efficient.
 848      *
 849      * @param  src
 850      *         The array from which $type$s are to be read
 851      *
 852      * @param  offset
 853      *         The offset within the array of the first $type$ to be read;
 854      *         must be non-negative and no larger than {@code array.length}
 855      *
 856      * @param  length
 857      *         The number of $type$s to be read from the given array;
 858      *         must be non-negative and no larger than
 859      *         {@code array.length - offset}
 860      *
 861      * @return  This buffer
 862      *
 863      * @throws  BufferOverflowException


 889      * invocation
 890      *
 891      * <pre>
 892      *     dst.put(a, 0, a.length) </pre>
 893      *
 894      * @param   src
 895      *          The source array
 896      *
 897      * @return  This buffer
 898      *
 899      * @throws  BufferOverflowException
 900      *          If there is insufficient space in this buffer
 901      *
 902      * @throws  ReadOnlyBufferException
 903      *          If this buffer is read-only
 904      */
 905     public final $Type$Buffer put($type$[] src) {
 906         return put(src, 0, src.length);
 907     }
 908 






















































































































































 909 #if[char]
 910 
 911     /**
 912      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
 913      *
 914      * <p> This method transfers $type$s from the given string into this
 915      * buffer.  If there are more $type$s to be copied from the string than
 916      * remain in this buffer, that is, if
 917      * <code>end&nbsp;-&nbsp;start</code>&nbsp;{@code >}&nbsp;{@code remaining()},
 918      * then no $type$s are transferred and a {@link
 919      * BufferOverflowException} is thrown.
 920      *
 921      * <p> Otherwise, this method copies
 922      * <i>n</i>&nbsp;=&nbsp;{@code end}&nbsp;-&nbsp;{@code start} $type$s
 923      * from the given string into this buffer, starting at the given
 924      * {@code start} index and at the current position of this buffer.  The
 925      * position of this buffer is then incremented by <i>n</i>.
 926      *
 927      * <p> In other words, an invocation of this method of the form
 928      * <code>dst.put(src,&nbsp;start,&nbsp;end)</code> has exactly the same effect


   1 /*
   2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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 #warn This file is preprocessed before being compiled
  27 
  28 package java.nio;
  29 
  30 #if[char]
  31 import java.io.IOException;
  32 #end[char]
  33 #if[streamableType]
  34 import java.util.Spliterator;
  35 import java.util.stream.StreamSupport;
  36 import java.util.stream.$Streamtype$Stream;
  37 #end[streamableType]
  38 
  39 import java.util.Objects;
  40 import jdk.internal.util.ArraysSupport;
  41 
  42 /**
  43  * $A$ $type$ buffer.
  44  *
  45  * <p> This class defines {#if[byte]?six:four} categories of operations upon
  46  * $type$ buffers:
  47  *
  48  * <ul>
  49  *
  50  *   <li><p> Absolute and relative {@link #get() <i>get</i>} and
  51  *   {@link #put($type$) <i>put</i>} methods that read and write
  52  *   single $type$s; </p></li>
  53  *
  54  *   <li><p> Absolute and relative {@link #get($type$[]) <i>bulk get</i>}
  55  *   methods that transfer contiguous sequences of $type$s from this buffer
  56  *   into an array; {#if[!byte]?and}</p></li>
  57  *
  58  *   <li><p> Absolute and relative {@link #put($type$[]) <i>bulk put</i>}
  59  *   methods that transfer contiguous sequences of $type$s from $a$
  60  *   $type$ array{#if[char]?, a string,} or some other $type$
  61  *   buffer into this buffer;{#if[!byte]? and} </p></li>
  62  *
  63 #if[byte]
  64  *
  65  *   <li><p> Absolute and relative {@link #getChar() <i>get</i>}
  66  *   and {@link #putChar(char) <i>put</i>} methods that read and
  67  *   write values of other primitive types, translating them to and from
  68  *   sequences of bytes in a particular byte order; </p></li>
  69  *
  70  *   <li><p> Methods for creating <i><a href="#views">view buffers</a></i>,
  71  *   which allow a byte buffer to be viewed as a buffer containing values of
  72  *   some other primitive type; and </p></li>
  73  *
  74 #end[byte]
  75  *
  76  *   <li><p> A method for {@link #compact compacting}
  77  *   $a$ $type$ buffer.  </p></li>
  78  *


 418      *         The array that will back this buffer
 419      *
 420      * @return  The new $type$ buffer
 421      */
 422     public static $Type$Buffer wrap($type$[] array) {
 423         return wrap(array, 0, array.length);
 424     }
 425 
 426 #if[char]
 427 
 428     /**
 429      * Attempts to read characters into the specified character buffer.
 430      * The buffer is used as a repository of characters as-is: the only
 431      * changes made are the results of a put operation. No flipping or
 432      * rewinding of the buffer is performed.
 433      *
 434      * @param target the buffer to read characters into
 435      * @return The number of characters added to the buffer, or
 436      *         -1 if this source of characters is at its end
 437      * @throws IOException if an I/O error occurs

 438      * @throws ReadOnlyBufferException if target is a read only buffer
 439      * @since 1.5
 440      */
 441     public int read(CharBuffer target) throws IOException {
 442         // Determine the number of bytes n that can be transferred
 443         int targetRemaining = target.remaining();
 444         int remaining = remaining();
 445         if (remaining == 0)
 446             return -1;
 447         int n = Math.min(remaining, targetRemaining);
 448         int limit = limit();
 449         // Set source limit to prevent target overflow
 450         if (targetRemaining < remaining)
 451             limit(position() + n);
 452         try {
 453             if (n > 0)
 454                 target.put(this);
 455         } finally {
 456             limit(limit); // restore real limit
 457         }


 745      * <p> This method transfers $type$s from this buffer into the given
 746      * destination array.  An invocation of this method of the form
 747      * {@code src.get(a)} behaves in exactly the same way as the invocation
 748      *
 749      * <pre>
 750      *     src.get(a, 0, a.length) </pre>
 751      *
 752      * @param   dst
 753      *          The destination array
 754      *
 755      * @return  This buffer
 756      *
 757      * @throws  BufferUnderflowException
 758      *          If there are fewer than {@code length} $type$s
 759      *          remaining in this buffer
 760      */
 761     public $Type$Buffer get($type$[] dst) {
 762         return get(dst, 0, dst.length);
 763     }
 764 
 765     /**
 766      * Absolute bulk <i>get</i> method.
 767      *
 768      * <p> This method copies {@code length} $type$s from this buffer to a
 769      * destination array, starting at the given {@code index} in this buffer
 770      * and the given {@code offset} in the array.  The position of this buffer
 771      * is unchanged.
 772      *
 773      * <p> An invocation of this method of the form
 774      * <code>src.get(index,&nbsp;dst,&nbsp;off,&nbsp;len)</code>
 775      * has exactly the same effect as the following loop except that it first
 776      * checks the consistency of the supplied parameters and it is potentially
 777      * much more efficient:
 778      *
 779      * <pre>{@code
 780      *     for (int i = off, j = index; i < off + len; i++, j++)
 781      *         dst[i] = src.get(j);
 782      * }</pre>
 783      *
 784      * @param  index
 785      *         The index from which the $type$s will be read
 786      *
 787      * @param  dst
 788      *         The destination array
 789      *
 790      * @param  offset
 791      *         The offset within the array of the first $type$ to be
 792      *         written; must be non-negative and no larger than
 793      *         {@code dst.length}
 794      *
 795      * @param  length
 796      *         The number of $type$s to be written to the given
 797      *         array; must be non-negative and no larger than the minimum of
 798      *         {@code dst.length - offset} and {@code limit() - index}
 799      *
 800      * @return  This buffer
 801      *
 802      * @throws  IndexOutOfBoundsException
 803      *          If the index is negative, {@code index + length > limit()},
 804      *          or the preconditions on the {@code offset} and {@code length}
 805      *          parameters do not hold
 806      *
 807      * @since 13
 808      */
 809     public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
 810         //System.out.println("Absolute bulk get");
 811         Objects.checkFromIndexSize(index, length, limit());
 812         Objects.checkFromIndexSize(offset, length, dst.length);
 813         int end = offset + length;
 814         for (int i = offset, j = index; i < end; i++, j++)
 815             dst[i] = get(j);
 816         return this;
 817     }
 818 
 819     /**
 820      * Absolute bulk <i>get</i> method.
 821      *
 822      * <p> This method transfers $type$s from this buffer into the given
 823      * destination array.  The position of this buffer is unchanged.  An
 824      * invocation of this method of the form
 825      * <code>src.get(index,&nbsp;dst)</code> behaves in exactly the same
 826      * way as the invocation
 827      *
 828      * <pre>
 829      *     src.get(index, dst, 0, dst.length) </pre>
 830      *
 831      * @param  index
 832      *         The index from which the $type$s will be read
 833      *
 834      * @param  dst
 835      *         The destination array
 836      *
 837      * @return  This buffer
 838      *
 839      * @throws  IndexOutOfBoundsException
 840      *          If the index is negative or
 841      *          {@code index + dst.length > limit()}.
 842      *
 843      * @since 13
 844      */
 845     public $Type$Buffer get(int index, $type$[] dst) {
 846         return get(index, dst, 0, dst.length);
 847     }
 848 
 849 
 850     // -- Bulk put operations --
 851 
 852     /**
 853      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
 854      *
 855      * <p> This method transfers the $type$s remaining in the given source
 856      * buffer into this buffer.  If there are more $type$s remaining in the
 857      * source buffer than in this buffer, that is, if
 858      * {@code src.remaining()}&nbsp;{@code >}&nbsp;{@code remaining()},
 859      * then no $type$s are transferred and a {@link
 860      * BufferOverflowException} is thrown.
 861      *
 862      * <p> Otherwise, this method copies
 863      * <i>n</i>&nbsp;=&nbsp;{@code src.remaining()} $type$s from the given
 864      * buffer into this buffer, starting at each buffer's current position.
 865      * The positions of both buffers are then incremented by <i>n</i>.
 866      *
 867      * <p> In other words, an invocation of this method of the form
 868      * {@code dst.put(src)} has exactly the same effect as the loop


 907      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
 908      *
 909      * <p> This method transfers $type$s into this buffer from the given
 910      * source array.  If there are more $type$s to be copied from the array
 911      * than remain in this buffer, that is, if
 912      * {@code length}&nbsp;{@code >}&nbsp;{@code remaining()}, then no
 913      * $type$s are transferred and a {@link BufferOverflowException} is
 914      * thrown.
 915      *
 916      * <p> Otherwise, this method copies {@code length} $type$s from the
 917      * given array into this buffer, starting at the given offset in the array
 918      * and at the current position of this buffer.  The position of this buffer
 919      * is then incremented by {@code length}.
 920      *
 921      * <p> In other words, an invocation of this method of the form
 922      * <code>dst.put(src,&nbsp;off,&nbsp;len)</code> has exactly the same effect as
 923      * the loop
 924      *
 925      * <pre>{@code
 926      *     for (int i = off; i < off + len; i++)
 927      *         dst.put(src[i]);
 928      * }</pre>
 929      *
 930      * except that it first checks that there is sufficient space in this
 931      * buffer and it is potentially much more efficient.
 932      *
 933      * @param  src
 934      *         The array from which $type$s are to be read
 935      *
 936      * @param  offset
 937      *         The offset within the array of the first $type$ to be read;
 938      *         must be non-negative and no larger than {@code array.length}
 939      *
 940      * @param  length
 941      *         The number of $type$s to be read from the given array;
 942      *         must be non-negative and no larger than
 943      *         {@code array.length - offset}
 944      *
 945      * @return  This buffer
 946      *
 947      * @throws  BufferOverflowException


 973      * invocation
 974      *
 975      * <pre>
 976      *     dst.put(a, 0, a.length) </pre>
 977      *
 978      * @param   src
 979      *          The source array
 980      *
 981      * @return  This buffer
 982      *
 983      * @throws  BufferOverflowException
 984      *          If there is insufficient space in this buffer
 985      *
 986      * @throws  ReadOnlyBufferException
 987      *          If this buffer is read-only
 988      */
 989     public final $Type$Buffer put($type$[] src) {
 990         return put(src, 0, src.length);
 991     }
 992 
 993     /**
 994      * Absolute bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
 995      *
 996      * <p> This method copies {@code length} $type$s into this buffer from a
 997      * source array, starting at the given {@code offset} in the array and the
 998      * given {@code index} of this buffer.  The position of this buffer is
 999      * unchanged.
1000      *
1001      * <p> An invocation of this method of the form
1002      * <code>dst.put(index,&nbsp;src,&nbsp;off,&nbsp;len)</code>
1003      * has exactly the same effect as the following loop except that it first
1004      * checks the consistency of the supplied parameters and it is potentially
1005      * much more efficient:
1006      *
1007      * <pre>{@code
1008      *     for (int i = off, j = index; i < off + len; i++, j++)
1009      *         dst.put(j, src[i]);
1010      * }</pre>
1011      *
1012      * @param  index
1013      *         The index at which the $type$s will be written
1014      *
1015      * @param  src
1016      *         The array from which $type$s are to be read
1017      *
1018      * @param  offset
1019      *         The offset within the array of the first $type$ to be read;
1020      *         must be non-negative and no larger than {@code array.length}
1021      *
1022      * @param  length
1023      *         The number of $type$s to be read from the given array;
1024      *         must be non-negative and no larger than the minimum of
1025      *         {@code array.length - offset} and {@code limit() - index}
1026      *
1027      * @return  This buffer
1028      *
1029      * @throws  IndexOutOfBoundsException
1030      *          If the index is negative, {@code index + length > limit()},
1031      *          or the preconditions on the {@code offset} and {@code length}
1032      *          parameters do not hold
1033      *
1034      * @throws  ReadOnlyBufferException
1035      *          If this buffer is read-only
1036      *
1037      * @since 13
1038      */
1039     public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
1040         //System.out.println("Absolute bulk put array");
1041         if (isReadOnly())
1042             throw new ReadOnlyBufferException();
1043         Objects.checkFromIndexSize(index, length, limit());
1044         Objects.checkFromIndexSize(offset, length, src.length);
1045         int end = offset + length;
1046         for (int i = offset, j = index; i < end; i++, j++)
1047             this.put(j, src[i]);
1048         return this;
1049     }
1050 
1051     /**
1052      * Absolute bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
1053      *
1054      * <p> This method copies $type$s into this buffer from the given source
1055      * array.  The position of this buffer is unchanged.  An invocation of this
1056      * method of the form <code>dst.put(index,&nbsp;src)</code>
1057      * behaves in exactly the same was as the invocation
1058      *
1059      * <pre>
1060      *     dst.put(index, src, 0, src.length); </pre>
1061      *
1062      * @param  index
1063      *         The index at which the $type$s will be written
1064      *
1065      * @param  src
1066      *         The array from which $type$s are to be read
1067      *
1068      * @return  This buffer
1069      *
1070      * @throws  IndexOutOfBoundsException
1071      *          If the index is negative, {@code index + length > limit()},
1072      *          or the preconditions on the {@code offset} and {@code length}
1073      *          parameters do not hold
1074      *
1075      * @throws  ReadOnlyBufferException
1076      *          If this buffer is read-only
1077      *
1078      * @since 13
1079      */
1080     public $Type$Buffer put(int index, $type$[] src) {
1081         return put(index, src, 0, src.length);
1082     }
1083 
1084     /**
1085      * Absolute bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
1086      *
1087      * <p> This method copies {@code length} $type$s into this buffer from a
1088      * source buffer, starting at the given {@code offset} in the buffer and the
1089      * given {@code index} of this buffer.  The positions of both buffers are
1090      * unchanged.
1091      *
1092      * <p> An invocation of this method of the form
1093      * <code>dst.put(index,&nbsp;src,&nbsp;off,&nbsp;len)</code>
1094      * has exactly the same effect as the following loop except that it first
1095      * checks the consistency of the supplied parameters and it is potentially
1096      * much more efficient:
1097      *
1098      * <pre>{@code
1099      *     for (int i = off, j = index; i < off + len; i++, j++)
1100      *         dst.put(j, src.get(i));
1101      * }</pre>
1102      *
1103      * @param  index
1104      *         The index at which the $type$s will be written
1105      *
1106      * @param  src
1107      *         The buffer from which $type$s are to be read
1108      *
1109      * @param  offset
1110      *         The offset within the buffer of the first $type$ to be read;
1111      *         must be non-negative and no larger than {@code src.limit()}
1112      *
1113      * @param  length
1114      *         The number of $type$s to be read from the given buffer;
1115      *         must be non-negative and no larger than the minimum of
1116      *         {@code src.limit() - offset} and {@code limit() - index}
1117      *
1118      * @return  This buffer
1119      *
1120      * @throws  IndexOutOfBoundsException
1121      *          If the index is negative, {@code index + length > limit()},
1122      *          or the preconditions on the {@code offset} and {@code length}
1123      *          parameters do not hold
1124      *
1125      * @throws  ReadOnlyBufferException
1126      *          If this buffer is read-only
1127      *
1128      * @since 13
1129      */
1130     public $Type$Buffer put(int index, $Type$Buffer src, int offset,
1131         int length) {
1132         //System.out.println("Absolute bulk put buffer");
1133         if (isReadOnly())
1134             throw new ReadOnlyBufferException();
1135         Objects.checkFromIndexSize(index, length, limit());
1136         int n = src.limit();
1137         Objects.checkFromIndexSize(offset, length, n);
1138         for (int i = offset, j = index; i < n; i++, j++)
1139             put(j, src.get(i));
1140         return this;
1141     }
1142 
1143 #if[char]
1144 
1145     /**
1146      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
1147      *
1148      * <p> This method transfers $type$s from the given string into this
1149      * buffer.  If there are more $type$s to be copied from the string than
1150      * remain in this buffer, that is, if
1151      * <code>end&nbsp;-&nbsp;start</code>&nbsp;{@code >}&nbsp;{@code remaining()},
1152      * then no $type$s are transferred and a {@link
1153      * BufferOverflowException} is thrown.
1154      *
1155      * <p> Otherwise, this method copies
1156      * <i>n</i>&nbsp;=&nbsp;{@code end}&nbsp;-&nbsp;{@code start} $type$s
1157      * from the given string into this buffer, starting at the given
1158      * {@code start} index and at the current position of this buffer.  The
1159      * position of this buffer is then incremented by <i>n</i>.
1160      *
1161      * <p> In other words, an invocation of this method of the form
1162      * <code>dst.put(src,&nbsp;start,&nbsp;end)</code> has exactly the same effect


< prev index next >