@VisibleForTesting
  static ByteBuffer resizeGap(ByteBuffer buffer,
                              int offset,
                              int oldGapSize,
                              int newGapSize) {
    int oldGapEndOffset = offset + oldGapSize;
    int newGapEndOffset = offset + newGapSize;
    int limitBefore = buffer.limit();
    if (newGapSize > oldGapSize) {//expand:
      ByteBuffer enlargedBuffer = ensureLimitAndData(buffer, limitBefore + (newGapSize - oldGapSize));
      enlargedBuffer.put(newGapEndOffset,
                         buffer, oldGapEndOffset, limitBefore - oldGapEndOffset);
      enlargedBuffer.limit(limitBefore + newGapSize - oldGapSize);
      return enlargedBuffer;
    }
    else if (newGapSize < oldGapSize) {//collapse:
      buffer.put(newGapEndOffset,
                 buffer, oldGapEndOffset, limitBefore - oldGapEndOffset);
      buffer.limit(limitBefore + (newGapSize - oldGapSize));
      return buffer;
    }
    else {//nothing to move: oldGap=newGap
      return buffer;
    }
  }
@VisibleForTesting
  static ByteBuffer resizeGap(ByteBuffer buffer,
                              int offset,
                              int oldGapSize,
                              int newGapSize)