protected void resizeArrayToFit(int newCount) {
        int steppedSize = buf.length;
        if (steppedSize == 0)
            steppedSize = 64;
        else if (steppedSize <= 1024)
            steppedSize *= 4;
        else if (steppedSize <= 4024)
            steppedSize *= 2;
        else if (steppedSize <= 2 * 1024 * 1024) {
            steppedSize *= 2;
            steppedSize &= (~0x0FFF);           // Fit on even 4KB pages
        } else if (steppedSize <= 4 * 1024 * 1024) {
            steppedSize = (steppedSize * 3) / 2;  // x 1.50
            steppedSize &= (~0x0FFF);           // Fit on even 4KB pages
        } else if (steppedSize <= 15 * 1024 * 1024) {
            steppedSize = (steppedSize * 5) / 4;  // x 1.25
            steppedSize &= (~0x0FFF);           // Fit on even 4KB pages
        } else {
            steppedSize = (steppedSize + (3 * 1024 * 1024));  // Go up in 3MB increments
            steppedSize &= (~0x0FFF);           // Fit on even 4KB pages
        }

        int newBufSize = Math.max(steppedSize, newCount);
        byte newBuf[] = allocateByteArray(newBufSize, false);
        System.arraycopy(buf, 0, newBuf, 0, count);
        buf = null;
        buf = newBuf;
    }