logger.debug("Adding uncompressed file...");
//add this uncompressed file to the archive
int bytesRead;
String entryName = currentFile.getName();
logger.debug("Zipping: " + entryName);
ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName);
newZipStream.putArchiveEntry(zipEntry);
while ((bytesRead = currentFileStream.read(buffer))!= -1) {
newZipStream.write(buffer, 0, bytesRead);
}
newZipStream.closeArchiveEntry();
} else {
logger.debug("Adding entries from compressed file...");
//read the entries from the zip file and copy them to the new zip archive
//so that we don't have to recompress them.
ZipArchiveInputStream currentZipStream = new ZipArchiveInputStream(currentFileStream);
ArchiveEntry currentEntry;
while ((currentEntry = currentZipStream.getNextEntry()) != null) {
String entryName = currentEntry.getName();
logger.debug("Zipping: " + entryName);
ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName);
try {
newZipStream.putArchiveEntry(zipEntry);
} catch (Exception e){
//duplicate names should never happen.
entryName = Math.round(Math.random() * 10000) + "_" + entryName;
ZipArchiveEntry zipEntry2 = new ZipArchiveEntry(entryName);
newZipStream.putArchiveEntry(zipEntry2);
}
int bytesRead;
while ((bytesRead = currentZipStream.read(buffer))!= -1) {
newZipStream.write(buffer, 0, bytesRead);