|
|
|
@ -43,14 +43,15 @@ public class FilesZipper
|
|
|
|
|
// This method is "synchronized" to avoid any future problems with shared-buffer, if the requests are asynchronous.
|
|
|
|
|
private static synchronized boolean zipAFile(String fileName, ZipOutputStream zos, String baseDir)
|
|
|
|
|
{
|
|
|
|
|
boolean shouldCloseEntry = false; // Useful in order to close the entry in case of an exception.
|
|
|
|
|
String fullFileName = baseDir + fileName;
|
|
|
|
|
try ( BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fullFileName), BUFFER_SIZE) ) {
|
|
|
|
|
zos.putNextEntry(new ZipEntry(fileName));
|
|
|
|
|
shouldCloseEntry = true;
|
|
|
|
|
int count;
|
|
|
|
|
while ( (count = bis.read(dataBuffer, 0, BUFFER_SIZE)) != -1 ) {
|
|
|
|
|
zos.write(dataBuffer, 0, count);
|
|
|
|
|
}
|
|
|
|
|
zos.closeEntry(); // close the entry here (not the ZipOutputStream)
|
|
|
|
|
} catch (FileNotFoundException fnfe) {
|
|
|
|
|
logger.error("Error zipping file: " + fullFileName, fnfe.getMessage());
|
|
|
|
|
return false;
|
|
|
|
@ -58,6 +59,14 @@ public class FilesZipper
|
|
|
|
|
if ( ! e.getMessage().contains("duplicate") )
|
|
|
|
|
logger.error("Error zipping file: " + fullFileName, e);
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
if ( shouldCloseEntry ) {
|
|
|
|
|
try {
|
|
|
|
|
zos.closeEntry(); // close the entry here (not the ZipOutputStream)
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
logger.error("", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|