/** * Sets the length of the file in blocks. The file will not be expanded if it * is already large enough. The file will be truncated to the correct length * when {@link #close} is called. * * @param nrBlocks the length of the file in blocks. * @throws IOException if an I/O error occurs. */ public void setNrBlocks(long nrBlocks) throws IOException { if (nrBlocks == this.nrBlocks) return; long prevNrBlocks = this.nrBlocks; super.setNrBlocks(nrBlocks); if (nrBlocks <= prevNrBlocks) return; // Call mapFile() if the file must grow in size. int nrRegions = (nrBlocks > 0) ? (int) ((((nrBlocks - 1) * blockSize) / stride) + 1) : 0; if (nrRegions > nrMappedRegions) { mapFile(nrRegions); } }