I have to create a method where I need to chunk files into multiple bytes.
examples byte[] into List<byte[]> , lets say each of it is size 1 MB (sizeMB=1 * 1024 * 1024)
so 5.2 MB file should be list of five 1MB and one 2KB. [2kb, 1MB, 1MB, 1MB, 1MB,1MB].
byte[] mainFile=getFIle(); List<bute[]> listofSplitBytes=getFileChunks(mainFile); public void list<bute[]> getFileChunks(byte[] mainFile) { int sizeMB = 1 * 1024 * 1024; // Split the files logic } I am trying to avoid adding, if then else ,to handle . I am trying to find if there is a cleaner way to do it, like using streams or something like that?
?…:or Math.max/min, but one way or another, a conditional construct is going to be necessary.