@@ -0,0 +1,3102 @@
+package com.llnw.storage.client.io;%0A%0Aimport java.util.Iterator;%0Aimport java.util.NoSuchElementException;%0A%0A%0Apublic class FixedChunks implements Iterable%3CChunk%3E %7B%0A%0A    //-------------------------------------------------------------%0A    // Constants%0A    //-------------------------------------------------------------%0A%0A    private static final long MINIMUM_CHUNK_SIZE = 16 * 1024 * 1024; // 16 MiB%0A    private static final long MAXIMUM_CHUNK_SIZE = 512 * 1024 * 1024; // 512 MiB%0A    private static final int TARGET_CHUNKS = 100;%0A%0A    //-------------------------------------------------------------%0A    // Variables - private final%0A    //-------------------------------------------------------------%0A%0A    public final long size;%0A    public final long chunkSize;%0A    public final int totalChunks;%0A%0A    //-------------------------------------------------------------%0A    // Constructors%0A    //-------------------------------------------------------------%0A%0A    public FixedChunks(long size) %7B%0A        this(size, MINIMUM_CHUNK_SIZE, MAXIMUM_CHUNK_SIZE);%0A    %7D%0A%0A%0A    public FixedChunks(long size, long minimumChunkSize, long maximumChunkSize) %7B%0A        this.size = size;%0A        final long baseChunkSize = size / TARGET_CHUNKS;%0A        if (baseChunkSize %3C minimumChunkSize) // Use fewer chunks to keep chunk size up%0A            chunkSize = Math.min(size, minimumChunkSize); // Chunk size can never be %3E size%0A        else if (baseChunkSize %3E maximumChunkSize) // Use more chunks to keep chunk size down%0A            chunkSize = maximumChunkSize;%0A        else%0A            chunkSize = baseChunkSize;%0A        totalChunks = (int)((size + chunkSize - 1) / chunkSize);%0A    %7D%0A%0A    //-------------------------------------------------------------%0A    // Methods - public%0A    //-------------------------------------------------------------%0A%0A    @Override%0A    public Iterator%3CChunk%3E iterator() %7B%0A        return new ChunkIterator();%0A    %7D%0A%0A    //-------------------------------------------------------------%0A    // Classes - private%0A    //-------------------------------------------------------------%0A%0A    private class ChunkIterator implements Iterator%3CChunk%3E %7B%0A%0A        //-------------------------------------------------------------%0A        // Variables - private%0A        //-------------------------------------------------------------%0A%0A        private int chunk = 0;%0A%0A        //-------------------------------------------------------------%0A        // Methods - public%0A        //-------------------------------------------------------------%0A%0A        @Override%0A        public boolean hasNext() %7B%0A            return chunk %3C totalChunks;%0A        %7D%0A%0A%0A        @Override%0A        public Chunk next() %7B%0A            if (!hasNext()) throw new NoSuchElementException();%0A            chunk++;%0A            final long offset = (chunk - 1) * chunkSize;%0A            final long length = size - offset %3E chunkSize ? chunkSize : size - offset;%0A            return new Chunk(chunk - 1, offset, length, true);%0A        %7D%0A%0A%0A        @Override%0A        public void remove() %7B%0A            throw new UnsupportedOperationException();%0A        %7D%0A    %7D%0A%7D%0A%0A

Add FixedChunks for multipart upload