int (int offset, int pageSize, int rawRecordSize) { int recordSizeRoundedUp = rawRecordSize; if (recordSizeRoundedUp % OFFSET_BUCKET != 0) { recordSizeRoundedUp = ((recordSizeRoundedUp / OFFSET_BUCKET + 1) * OFFSET_BUCKET); } final int occupiedOnPage = offset + recordSizeRoundedUp; final int remainedOnPage = pageSize - occupiedOnPage; if (0 < remainedOnPage && remainedOnPage < OFFSET_BUCKET) { //we can't squeeze even the smallest record into remaining space, so just merge it into current record recordSizeRoundedUp += remainedOnPage; } assert recordSizeRoundedUp >= rawRecordSize : "roundedUpRecordSize(=" + recordSizeRoundedUp + ") must be >= rawRecordSize(=" + rawRecordSize + ")"; return recordSizeRoundedUp; }