Search code examples
javafilejarchunked-encodingchunked

Facing issue while chunking then merging the jar files


I have one jar file for example apache-cassandra-3.11.6.jar. Firstly i split/chunked into mutiple jars like below :

apache-cassandra1.jar apache-cassandra2.jar apache-cassandra3.jar apache-cassandra4.jar apache-cassandra5.jar apache-cassandra6.jar

Then i reassemble them again into new Jar file i.e apache-cassandra_Merged.jar. Now the problem comes.

When i compare the original jar file i.e apache-cassandra-3.11.6.jar with new Jar file i.e apache-cassandra_Merged.jar. then it is not matching.

The newly created jar file which is apache-cassandra_Merged.jar, it's size also reduced.

Please find below my code for your reference :

/// Chunking/spliting into mutiple jars
Path path = Paths.get("/Original_Jar/apache-cassandra-3.11.6.jar");
byte [] data = Files.readAllBytes(path); // Will read all bytes at once

Now divide total bytes into equal part and then write in each small jars one by one.

int count = 0;
for(byte[] rangeData : Arrays.copyOfRange(data, rangeSTART, rangeEND)){
        FileOutputStream fileOutputStream1 = new FileOutputStream("/Cassandra_Image/Chunked_Jar/apache-cassandra"+count+".jar");
        fileOutputStream1.write(rangeData);
}

//Merging back to one jar For merging i used the same way. Created array of byte for each small/chunked jars and written into FileOutputStream("/Merged_Jar/apache-cassandra_Merged.jar") one by one.

Please let me know if i should use some other method/algorithm to split jar and reassemble it again which will make sure the originality of data after chunking and merging as well.

Note : Actually i want to transfer the jars to any server/directory where i should transfer a jar with limited size so for big size jars i need to split into small jars and send them one by one and then again reassemble them in target directory/place and it should be as original jar.

Thanks in advance.


Solution

  • I am able to solve the issue with shell scripting. Written below code in my shell script file and run through my java code.

    split -b 1000000 src.jar target.jar
    cat src.jaraa src.jarab src.jarac src.jarad src.jarae > merged.jar
    

    And compare with any algorithm like sha256 checksum will work fine and it shows equal. and size also equal.