< prev index next >

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

Print this page

        

*** 1127,1136 **** --- 1127,1197 ---- */ public $Type$Buffer put(int index, $type$[] src) { return put(index, src, 0, src.length); } + /** + * Absolute bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>. + * + * <p> This method transfers {@code length} $type$s into this buffer + * from the source buffer, starting at the given {@code srcIndex} in the + * source buffer and the given {@code index} in this buffer. The positions + * of both buffers are unchanged. If the source buffer is this buffer and + * the source and target intervals overlap, then the buffer elements in the + * target range will be overwritten by those in the source range of the + * same buffer which could lead to unexpected results. + * + * <p> An invocation of this method of the form + * <code>dst.put(index,&nbsp;src,&nbsp;srcIndex,&nbsp;length)</code> + * has exactly the same effect as the following loop except that it first + * checks the consistency of the supplied parameters and it is potentially + * much more efficient: + * + * <pre>{@code + * for (int i = srcIndex, j = index; i < srcIndex + length; i++, j++) + * dst.put(j, src.get(i)); + * }</pre> + * + * @param index + * The index in this buffer at which the first $type$ will be + * written; must be non-negative and less than {@code limit()} + * + * @param src + * The buffer from which $type$s are to be read + * + * @param srcIndex + * The index within the source buffer of the first $type$ to be + * read; must be non-negative and less than {@code src.limit()} + * + * @param length + * The number of $type$s to be read from the given buffer; + * must be non-negative and no larger than the smaller of + * {@code limit() - index} and {@code src.limit() - srcIndex} + * + * @return This buffer + * + * @throws IndexOutOfBoundsException + * If the preconditions on the {@code index}, {@code srcIndex}, and + * {@code length} parameters do not hold + * + * @throws ReadOnlyBufferException + * If this buffer is read-only + * + * @since 15 + */ + public $Type$Buffer put(int index, $Type$Buffer src, int srcIndex, + int length) { + if (isReadOnly()) + throw new ReadOnlyBufferException(); + Objects.checkFromIndexSize(index, length, limit()); + Objects.checkFromIndexSize(srcIndex, length, src.limit()); + int end = srcIndex + length; + for (int i = srcIndex, j = index; i < end; i++, j++) + this.put(j, src.get(i)); + return this; + } + #if[char] /** * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>. *
< prev index next >