--- old/src/java.base/share/classes/java/nio/X-Buffer.java.template 2019-02-08 14:19:27.000000000 -0800 +++ new/src/java.base/share/classes/java/nio/X-Buffer.java.template 2019-02-08 14:19:27.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,7 @@ import java.util.stream.$Streamtype$Stream; #end[streamableType] +import java.util.Objects; import jdk.internal.util.ArraysSupport; /** @@ -50,11 +51,11 @@ * {@link #put($type$) put} methods that read and write * single $type$s;

* - *
  • Relative {@link #get($type$[]) bulk get} + *

  • Absolute and relative {@link #get($type$[]) bulk get} * methods that transfer contiguous sequences of $type$s from this buffer * into an array; {#if[!byte]?and}

  • * - *
  • Relative {@link #put($type$[]) bulk put} + *

  • Absolute and relative {@link #put($type$[]) bulk put} * methods that transfer contiguous sequences of $type$s from $a$ * $type$ array{#if[char]?, a string,} or some other $type$ * buffer into this buffer;{#if[!byte]? and}

  • @@ -434,7 +435,6 @@ * @return The number of characters added to the buffer, or * -1 if this source of characters is at its end * @throws IOException if an I/O error occurs - * @throws NullPointerException if target is null * @throws ReadOnlyBufferException if target is a read only buffer * @since 1.5 */ @@ -762,6 +762,90 @@ return get(dst, 0, dst.length); } + /** + * Absolute bulk get method. + * + *

    This method copies {@code length} $type$s from this buffer to a + * destination array, starting at the given {@code index} in this buffer + * and the given {@code offset} in the array. The position of this buffer + * is unchanged. + * + *

    An invocation of this method of the form + * src.get(index, dst, off, len) + * 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: + * + *

    {@code
    +     *     for (int i = off, j = index; i < off + len; i++, j++)
    +     *         dst[i] = src.get(j);
    +     * }
    + * + * @param index + * The index from which the $type$s will be read + * + * @param dst + * The destination array + * + * @param offset + * The offset within the array of the first $type$ to be + * written; must be non-negative and no larger than + * {@code dst.length} + * + * @param length + * The number of $type$s to be written to the given + * array; must be non-negative and no larger than the minimum of + * {@code dst.length - offset} and {@code limit() - index} + * + * @return This buffer + * + * @throws IndexOutOfBoundsException + * If the index is negative, {@code index + length > limit()}, + * or the preconditions on the {@code offset} and {@code length} + * parameters do not hold + * + * @since 13 + */ + public $Type$Buffer get(int index, $type$[] dst, int offset, int length) { + //System.out.println("Absolute bulk get"); + Objects.checkFromIndexSize(index, length, limit()); + Objects.checkFromIndexSize(offset, length, dst.length); + int end = offset + length; + for (int i = offset, j = index; i < end; i++, j++) + dst[i] = get(j); + return this; + } + + /** + * Absolute bulk get method. + * + *

    This method transfers $type$s from this buffer into the given + * destination array. The position of this buffer is unchanged. An + * invocation of this method of the form + * src.get(index, dst) behaves in exactly the same + * way as the invocation + * + *

    +     *     src.get(index, dst, 0, dst.length) 
    + * + * @param index + * The index from which the $type$s will be read + * + * @param dst + * The destination array + * + * @return This buffer + * + * @throws IndexOutOfBoundsException + * If the index is negative or + * {@code index + dst.length > limit()}. + * + * @since 13 + */ + public $Type$Buffer get(int index, $type$[] dst) { + return get(index, dst, 0, dst.length); + } + // -- Bulk put operations -- @@ -840,7 +924,7 @@ * *
    {@code
          *     for (int i = off; i < off + len; i++)
    -     *         dst.put(a[i]);
    +     *         dst.put(src[i]);
          * }
    * * except that it first checks that there is sufficient space in this @@ -906,6 +990,156 @@ return put(src, 0, src.length); } + /** + * Absolute bulk put method  (optional operation). + * + *

    This method copies {@code length} $type$s into this buffer from a + * source array, starting at the given {@code offset} in the array and the + * given {@code index} of this buffer. The position of this buffer is + * unchanged. + * + *

    An invocation of this method of the form + * dst.put(index, src, off, len) + * 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: + * + *

    {@code
    +     *     for (int i = off, j = index; i < off + len; i++, j++)
    +     *         dst.put(j, src[i]);
    +     * }
    + * + * @param index + * The index at which the $type$s will be written + * + * @param src + * The array from which $type$s are to be read + * + * @param offset + * The offset within the array of the first $type$ to be read; + * must be non-negative and no larger than {@code array.length} + * + * @param length + * The number of $type$s to be read from the given array; + * must be non-negative and no larger than the minimum of + * {@code array.length - offset} and {@code limit() - index} + * + * @return This buffer + * + * @throws IndexOutOfBoundsException + * If the index is negative, {@code index + length > limit()}, + * or the preconditions on the {@code offset} and {@code length} + * parameters do not hold + * + * @throws ReadOnlyBufferException + * If this buffer is read-only + * + * @since 13 + */ + public $Type$Buffer put(int index, $type$[] src, int offset, int length) { + //System.out.println("Absolute bulk put array"); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + Objects.checkFromIndexSize(index, length, limit()); + Objects.checkFromIndexSize(offset, length, src.length); + int end = offset + length; + for (int i = offset, j = index; i < end; i++, j++) + this.put(j, src[i]); + return this; + } + + /** + * Absolute bulk put method  (optional operation). + * + *

    This method copies $type$s into this buffer from the given source + * array. The position of this buffer is unchanged. An invocation of this + * method of the form dst.put(index, src) + * behaves in exactly the same was as the invocation + * + *

    +     *     dst.put(index, src, 0, src.length); 
    + * + * @param index + * The index at which the $type$s will be written + * + * @param src + * The array from which $type$s are to be read + * + * @return This buffer + * + * @throws IndexOutOfBoundsException + * If the index is negative, {@code index + length > limit()}, + * or the preconditions on the {@code offset} and {@code length} + * parameters do not hold + * + * @throws ReadOnlyBufferException + * If this buffer is read-only + * + * @since 13 + */ + public $Type$Buffer put(int index, $type$[] src) { + return put(index, src, 0, src.length); + } + + /** + * Absolute bulk put method  (optional operation). + * + *

    This method copies {@code length} $type$s into this buffer from a + * source buffer, starting at the given {@code offset} in the buffer and the + * given {@code index} of this buffer. The positions of both buffers are + * unchanged. + * + *

    An invocation of this method of the form + * dst.put(index, src, off, len) + * 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: + * + *

    {@code
    +     *     for (int i = off, j = index; i < off + len; i++, j++)
    +     *         dst.put(j, src.get(i));
    +     * }
    + * + * @param index + * The index at which the $type$s will be written + * + * @param src + * The buffer from which $type$s are to be read + * + * @param offset + * The offset within the buffer of the first $type$ to be read; + * must be non-negative and no larger 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 minimum of + * {@code src.limit() - offset} and {@code limit() - index} + * + * @return This buffer + * + * @throws IndexOutOfBoundsException + * If the index is negative, {@code index + length > limit()}, + * or the preconditions on the {@code offset} and {@code length} + * parameters do not hold + * + * @throws ReadOnlyBufferException + * If this buffer is read-only + * + * @since 13 + */ + public $Type$Buffer put(int index, $Type$Buffer src, int offset, + int length) { + //System.out.println("Absolute bulk put buffer"); + if (isReadOnly()) + throw new ReadOnlyBufferException(); + Objects.checkFromIndexSize(index, length, limit()); + int n = src.limit(); + Objects.checkFromIndexSize(offset, length, n); + for (int i = offset, j = index; i < n; i++, j++) + put(j, src.get(i)); + return this; + } + #if[char] /**