/** * Guess in how many chunks we should split this file. Should return the same value consistently * for the same file (segments are immutable) so that a full segment can be rebuilt from the upper * layers without anyone actually specifying the chunks numbers. */ private int figureChunksNumber(String fileName) throws IOException { long fileLength = directory.fileLength(fileName); return figureChunksNumber(fileName, fileLength, autoChunkSize); }
/** * Guess in how many chunks we should split this file. Should return the same value consistently * for the same file (segments are immutable) so that a full segment can be rebuilt from the upper * layers without anyone actually specifying the chunks numbers. */ private int figureChunksNumber(String fileName) throws IOException { long fileLength = directory.fileLength(fileName); return figureChunksNumber(fileName, fileLength, autoChunkSize); }
/** * Guess in how many chunks we should split this file. Should return the same value consistently * for the same file (segments are immutable) so that a full segment can be rebuilt from the upper * layers without anyone actually specifying the chunks numbers. */ private int figureChunksNumber(String fileName) throws IOException { long fileLength = directory.fileLength(fileName); return figureChunksNumber(fileName, fileLength, autoChunkSize); }
/** * Index segment files might be larger than 2GB; so it's possible to have an autoChunksize * which is too low to contain all bytes in a single array (overkill anyway). * In this case we ramp up and try splitting with larger chunkSize values. */ public static int figureChunksNumber(final String fileName, final long fileLength, int chunkSize) { if (chunkSize < 0) { throw new IllegalStateException("Overflow in rescaling chunkSize. File way too large?"); } final long numChunks = (fileLength % chunkSize == 0) ? (fileLength / chunkSize) : (fileLength / chunkSize) + 1; if (numChunks > Integer.MAX_VALUE) { log.rescalingChunksize(fileName, fileLength, chunkSize); chunkSize = 32 * chunkSize; return figureChunksNumber(fileName, fileLength, chunkSize); } else { return (int)numChunks; } }
/** * Index segment files might be larger than 2GB; so it's possible to have an autoChunksize * which is too low to contain all bytes in a single array (overkill anyway). * In this case we ramp up and try splitting with larger chunkSize values. */ private static int figureChunksNumber(final String fileName, final long fileLength, int chunkSize) { if (chunkSize < 0) { throw new IllegalStateException("Overflow in rescaling chunkSize. File way too large?"); } final long numChunks = (fileLength / chunkSize); if (numChunks > Integer.MAX_VALUE) { log.rescalingChunksize(fileName, fileLength, chunkSize); chunkSize = 32 * chunkSize; return figureChunksNumber(fileName, fileLength, chunkSize); } else { return (int)numChunks; } }
/** * Index segment files might be larger than 2GB; so it's possible to have an autoChunksize * which is too low to contain all bytes in a single array (overkill anyway). * In this case we ramp up and try splitting with larger chunkSize values. */ public static int figureChunksNumber(final String fileName, final long fileLength, int chunkSize) { if (chunkSize < 0) { throw new IllegalStateException("Overflow in rescaling chunkSize. File way too large?"); } final long numChunks = (fileLength % chunkSize == 0) ? (fileLength / chunkSize) : (fileLength / chunkSize) + 1; if (numChunks > Integer.MAX_VALUE) { log.rescalingChunksize(fileName, fileLength, chunkSize); chunkSize = 32 * chunkSize; return figureChunksNumber(fileName, fileLength, chunkSize); } else { return (int)numChunks; } }
@Test public void testRescalingMath() { Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", 0, 1), 0); Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", 1, 1), 1); Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", 2, 1), 2); int MB = 1024*1024; Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", 0, MB), 0); Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", 1, MB), 1); Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", 2, MB), 1); Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", MB, MB), 1); Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", MB+1, MB), 2); Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", MB+MB, MB), 2); Assert.assertEquals(DirectoryLoaderAdaptor.figureChunksNumber("", MB+MB+1, MB), 3); }
int numChunksInt = figureChunksNumber(fileName); for (int i = 0; i < numChunksInt; i++) {
int numChunksInt = figureChunksNumber(fileName); for (int i = 0; i < numChunksInt; i++) {
int numChunksInt = figureChunksNumber(fileName); for (int i = 0; i < numChunksInt; i++) {