private void insertIntoDynamicTable(int index, Header entry) throws IOException {
            mHeaders.add(entry);

            int delta = entry.hpackSize();
            if (index != -1) { // Index -1 == new header.
                Header header = mDynamicTable[dynamicTableIndex(index)];
                if (header == null) {
                    throw new IOException("Hpack read headers failed: insert dynamic table failed!");
                }
                delta -= header.hpackSize();
            }

            // if the new or replacement header is too big, drop all entries.
            if (delta > mMaxDynamicTableByteCount) {
                clearDynamicTable();
                return;
            }

            // Evict headers to the required length.
            int bytesToRecover = (mDynamicTableByteCount + delta) - mMaxDynamicTableByteCount;
            int entriesEvicted = evictToRecoverBytes(bytesToRecover);

            if (index == -1) { // Adding a value to the dynamic table.
                if (mHeaderCount + 1 > mDynamicTable.length) { // Need to grow the dynamic table.
                    Header[] doubled = new Header[mDynamicTable.length * 2];
                    System.arraycopy(mDynamicTable, 0, doubled, mDynamicTable.length,
                            mDynamicTable.length);
                    mNextHeaderIndex = mDynamicTable.length - 1;
                    mDynamicTable = doubled;
                }
                index = mNextHeaderIndex--;
                mDynamicTable[index] = entry;
                mHeaderCount++;
            } else { // Replace value at same position.
                index += dynamicTableIndex(index) + entriesEvicted;
                mDynamicTable[index] = entry;
            }
            mDynamicTableByteCount += delta;
        }
Read and write HPACK v10.

https://httpwg.org/specs/rfc7540.html#HeaderBlock

This implementation uses an array for the dynamic table and a list for indexed entries.  Dynamic
entries are added to the array, starting in the last position moving forward.  When the array
fills, it is doubled.

@author Megatron King
@since 2019/1/5 20:13
netbare-core/src/main/java/com/github/megatronking/netbare/http2/Hpack.java