I'd like to break up a single zip file that holds multiple files and create a zip file for each of the ZipEntries. That is: MainZipFile.zip ---> Zip1.zip, Zip2.zip, Zip3.zip Where the (right-hand-side) RHS zip files correspond to ZipEntrys inside MainZipFile.zip.
I'm using Java, and I'd like to do it without decompressing and re-compressing, which is the obvious solution. I'm not even sure if this is even practically possible.
I was thinking of creating empty RHS zip files, then using ZipInputStream to read the contents of an ZipEntry in MainZipFile.zip and deposit the contents into the corresponding RHS zip file, but I can't figure it out.
Edit 1:
final int BUFFER_SIZE_IN_BYTES=2*1024; //2KB
void tryReading(){
String filepath = getTempFilepath();
ZipFile mainZipFile = new ZipFile(filepath);
InputStream inForEntry = getInputStreamForEntryWithName(checkpoint.getFilePath(), mainZipFile);
ZipInputStream zin = new ZipInputStream(inForEntry);
byte[] data = new byte[BUFFER_SIZE_IN_BYTES];
int countOfBytesRead = zin.read(data); //returns -1
zin.getNextEntry();
countOfBytesRead = zin.read(data);//returns -1
}
private InputStream getInputStreamForEntryWithName(String name, ZipFile mainZipFile) throws IOException {
ZipEntry entry = mainZipFile.getEntry(name);
return mainZipFile.getInputStream(entry);
}