code: public int setBytes(int index, ScatteringByteChannel in, int length)
              throws IOException
      {
          checkPositionIndexes(index, index + length, this.length);
          index += offset;
          ByteBuffer buf = ByteBuffer.wrap(data, index, length);
          int readBytes = 0;
  
          do {
              int localReadBytes;
              try {
                  localReadBytes = in.read(buf);
              }
              catch (ClosedChannelException e) {
                  localReadBytes = -1;
              }
              if (localReadBytes < 0) {
                  if (readBytes == 0) {
                      return -1;
                  }
                  else {
                      break;
                  }
              }
              else if (localReadBytes == 0) {
                  break;
              }
              readBytes += localReadBytes;
          } while (readBytes < length);
  
          return readBytes;
      }
docs: Transfers the content of the specified source channel to this buffer
  starting at the specified absolute {@code index}.
  
  @param length the maximum number of bytes to transfer
  @return the actual number of bytes read in from the specified channel.
  {@code -1} if the specified channel is closed.
  @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
  if {@code index + length} is greater than {@code this.capacity}
  @throws java.io.IOException if the specified channel threw an exception during I/O