(init): Starting the project
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility methods related to chunk creation.
|
||||
*/
|
||||
public class ChunkUtils {
|
||||
|
||||
private ChunkUtils() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the total file size into a list of chunks.
|
||||
* Chunk sizes are as even as possible.
|
||||
* If the size is not exactly divisible, the last chunk gets the remainder.
|
||||
*
|
||||
* @param totalSizeMB total file size in MB
|
||||
* @param chunkCount number of chunks
|
||||
* @return list of ChunkStatus objects
|
||||
*/
|
||||
public static List<ChunkStatus> createChunks(int totalSizeMB, int chunkCount) {
|
||||
List<ChunkStatus> chunks = new ArrayList<>();
|
||||
|
||||
if (totalSizeMB <= 0 || chunkCount <= 0) {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
int baseChunkSize = totalSizeMB / chunkCount;
|
||||
int remainder = totalSizeMB % chunkCount;
|
||||
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
int chunkSize = baseChunkSize;
|
||||
|
||||
if (i == chunkCount - 1) {
|
||||
chunkSize += remainder;
|
||||
}
|
||||
|
||||
// Create one ChunkStatus object for each chunk.
|
||||
// chunkId is the chunk number, and chunkSize is this chunk's total size.
|
||||
chunks.add(new ChunkStatus(i + 1, chunkSize));
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user