Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8248431

(bf) Add absolute bulk put methods which accept a source Buffer



    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 16
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Compatibility Kind:
    • Compatibility Risk:
    • Compatibility Risk Description:
      A new method in classes that cannot be extended outside of the java.nio package so there is no compatibility risk.
    • Interface Kind:
      Java API
    • Scope:



      Add a method to write a sequence of values to a buffer from another buffer starting at an absolute position in each buffer.


      The java.nio.$Type$Buffer classes, where $Type$ is in {Byte, Char, Double, Float, Int, Long, Short}, currently define a method to perform a relative bulk put into a buffer of a sequence of values from another buffer. This method operates with respect to the current positions of the buffers and the positions are updated accordingly before the method returns. There is however no method to write a sequence of values from one buffer into another starting at absolute offsets in the source and target buffers and without affecting the position of either buffer. This is asymmetric with the bulk methods which write into the buffer from a source array: there are methods in that case to perform the write either relative to the buffer's position (relative bulk put) or without affecting the position (absolute bulk put).


      Add to the $Type$Buffer classes an absolute bulk put method which accepts a $Type$Buffer as its data source.


      The normative version of the proposed change is in the attached specdiff and webrev archives. The following is an example for ByteBuffer:

      public ByteBuffer put​(int index, ByteBuffer src, int offset, int length)
      Absolute bulk put method  (optional operation).
      This method transfers length bytes into this buffer from the given source buffer, starting at the given offset in the source buffer and the given index in this buffer. The positions of both buffers are unchanged.
      In other words, an invocation of this method of the form dst.put(index, src, offset, length) has exactly the same effect as the loop
       for (int i = offset, j = index; i < offset + length; i++, j++)
           dst.put(j, src.get(i));
      except that it first checks the consistency of the supplied parameters and it is potentially much more efficient. If this buffer and the source buffer share the same backing array or memory, then the result will be as if the source elements were first copied to an intermediate location before being written into this buffer.
          index - The index in this buffer at which the first byte will be written; must be non-negative and less than limit()
          src - The buffer from which bytes are to be read
          offset - The index within the source buffer of the first byte to be read; must be non-negative and less than src.limit()
          length - The number of bytes to be read from the given buffer; must be non-negative and no larger than the smaller of limit() - index and src.limit() - offset
          This buffer
          IndexOutOfBoundsException - If the preconditions on the index, offset, and length parameters do not hold
          ReadOnlyBufferException - If this buffer is read-only


          Issue Links



              bpb Brian Burkhalter
              bpb Brian Burkhalter
              Reviewed By:
              Martin Buchholz, Roger Riggs
              0 Vote for this issue
              3 Start watching this issue