Часть, которая загружает и вставляет файлы в zip-архив:
Код: Выделить всё
private Thread getDownloadAndZipThread(List keys, String filename, ZipFile zip, ZipParameters parameters) {
return new Thread(() -> {
long start = System.currentTimeMillis();
try (final ZipOutputStream zipOutputStream = new ZipOutputStream(pipedOutputStream)){
keys.forEach(key -> {
//logger.log("\nprocessing file: " + key);
try {
parameters.setFileNameInZip(key);
zipOutputStream.putNextEntry(parameters);
pipedOutputStream.write(s3Service.getFile(key, BUCKET_NAME).readAllBytes());
zipOutputStream.closeEntry();
//zip.addStream(IOUtils.copy(s3Service.getFile(key, BUCKET_NAME), pipedOutputStream), parameters);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (Exception e) {
logger.log("\nZipService - getDownloadAndZipThread - error: " + e);
}
long executedTime = System.currentTimeMillis() - start;
logger.log("\nZipService - getDownloadAndZipThread - execution time: " + executedTime);
});
}
Код: Выделить всё
private Thread getS3Out(String filename) {
return new Thread(() -> {
long start = System.currentTimeMillis();
try {
s3Service.multipartUpload(filename, BUCKET_NAME, pipedInputStream);
pipedInputStream.close();
} catch (final Exception all) {
logger.log("\nFailed to process outputStream due to error: " + all + "\n");
System.exit(-3);
}
long executedTime = System.currentTimeMillis() - start;
logger.log("\nZipService - getS3Out - execution time: " + executedTime);
});
}
Код: Выделить всё
String filename = generateZipName();
ZipFile zip = new ZipFile(filename);
ZipParameters parameters = new ZipParameters();
parameters.setCompressionLevel(CompressionLevel.FASTEST);
final Thread downloadAndZip = getDownloadAndZipThread(keys, filename, zip, parameters);
final Thread upload = getS3Out(filename);
downloadAndZip.start();
upload.start();
try {
downloadAndZip.join();
upload.join();
} catch (InterruptedException e) {
logger.log("ZipService - failed to join thread due to error: " + e);
throw new RuntimeException(e);
}
Zip4J ZipOutputStream вместо этого занимает 80 секунд в том же цикле.
Оба варианта были протестированы на 16 файлах общим размером 1,6 ГБ.
Мне нужно как-то исправить проблему с поврежденным zip-файлом для случая Zip4j.
Подробнее здесь: https://stackoverflow.com/questions/752 ... -zip-and-u