ChunkableContent implements Iterable<ChunkInputStream>, Iterator<ChunkInputStream> { protected int calculateBufferSize(long maxChunkSize) { final int KB = 1000; if (maxChunkSize % KB != 0) { String m = "MaxChunkSize must be multiple of " + KB + ": " + maxChunkSize; log.error(m); throw new DuraCloudRuntimeException(m); } long size = maxChunkSize; for (int i = 1; i <= maxChunkSize; i++) { if ((maxChunkSize % i == 0) && ((maxChunkSize / i) <= (8 * KB))) { size = maxChunkSize / i; break; } } log.debug("Buf size: " + size + " for maxChunkSize: " + maxChunkSize); return (int) size; } ChunkableContent(String contentId,
                            InputStream largeStream,
                            long contentSize,
                            long maxChunkSize);  ChunkableContent(String contentId,
                            String contentMimetype,
                            InputStream largeStream,
                            long contentSize,
                            long maxChunkSize); boolean hasNext(); ChunkInputStream next(); void remove(); Iterator<ChunkInputStream> iterator(); void setPreserveChunkMD5s(boolean preserveChunkMD5s); long getMaxChunkSize(); ChunksManifest getManifest(); ChunksManifest finalizeManifest();  }
@Test public void testCalculateBufferSize() { for (long i = 1000; i < 5000000000l; i += (1000 + i)) { int bufferSize = chunkable.calculateBufferSize(i); Assert.assertTrue(bufferSize <= 8000); Assert.assertEquals(0, i % bufferSize); } try { chunkable.calculateBufferSize(500); Assert.fail("Exception expected"); } catch (DuraCloudRuntimeException e) { } try { chunkable.calculateBufferSize(12345); Assert.fail("Exception expected"); } catch (DuraCloudRuntimeException e) { } }