code: public int setBytes(int index, InputStream in, int length)
              throws IOException
      {
          checkPositionIndexes(index, index + length, this.length);
          index += offset;
          int readBytes = 0;
          do {
              int localReadBytes = in.read(data, index, length);
              if (localReadBytes < 0) {
                  if (readBytes == 0) {
                      return -1;
                  }
                  else {
                      break;
                  }
              }
              readBytes += localReadBytes;
              index += localReadBytes;
              length -= localReadBytes;
          } while (length > 0);
  
          return readBytes;
      }
docs: Transfers the content of the specified source stream to this buffer
  starting at the specified absolute {@code index}.
  
  @param length the 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 stream threw an exception during I/O