I want somehow to add files into inner zip entry. Following structure of zip file looks like this:
input-zip-file
|-- directory/
| |-- zipfile.zip -
| | |-- files.txt - *How can i get these entries to my zipfile.zip*
| | |-- files.txt
It's only small piece of zip file. I walking through zip file and check if entry has more files inside. What I've done so far
snippet
private void handleZipFile(ZipFile input) throws IOException {
input.stream()
.forEach(entry -> {
try {
InputStream in = input.getInputStream(entry);
ZipInputStream zis = new ZipInputStream(in);
zos.putNextEntry(new ZipEntry(entry.getName()));
handleInnerZipEntry(entryName, zis, zos);
zos.closeEntry();
in.close();
zis.close();
zos.flush();
} catch (IOException e) {
e.printStackTrace());
}
}
);
zos.close();
}
handleInnerZip
private void handleInnerZipEntry(String entryPath, ZipInputStream in, ZipOutputStream out) throws IOException {
try {
ZipEntry entry = in.getNextEntry();
while (entry != null) {
out.putNextEntry(new ZipEntry(entry.getName())); // Need to put files.txt files
if (entry.getSize() > 0 && entry.getName().endsWith("zip")) {
ZipInputStream recursiveIn = new ZipInputStream(in);
ZipOutputStream recursiveOut = new ZipOutputStream(out);
handleInnerZipEntry(entryPath, recursiveIn, recursiveOut);
recursiveOut.flush();
} else if (entry.getSize() > 0 && !(entry.isDirectory())) {
}
in.closeEntry();
entry = in.getNextEntry();
}
} catch (IOException e) {
CustomLogger.error("IOException: " + e.getLocalizedMessage());
}
}