void (final long max) { long realSize = realSize(); if (max <= realSize) return; long suggestedSize; if (realSize == 0) { suggestedSize = doRoundToFactor(Math.max(myInitialSize, max)); } else { suggestedSize = Math.max(realSize + 1, 2); // suggestedSize should increase with int multiplication on 1.625 factor while (max > suggestedSize) { long newSuggestedSize = suggestedSize * 13 >> 3; if (newSuggestedSize >= Integer.MAX_VALUE) { suggestedSize += suggestedSize / 5; } else { suggestedSize = newSuggestedSize; } } suggestedSize = doRoundToFactor(suggestedSize); } try { myStorage.resize(suggestedSize); } catch (IOException e) { throw new RuntimeException(e); } }