use of com.checkmarx.sdk.utils.zip.NewCxZipFile in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class ScaClientHelper method zipDirectoryAndFingerprints.
private File zipDirectoryAndFingerprints(String sourceDir, List<String> paths, CxSCAScanFingerprints fingerprints) throws IOException {
File result = config.getZipFile();
if (result != null) {
return result;
}
File tempFile = getZipFile();
log.debug("Collecting files to zip archive: {}", tempFile.getAbsolutePath());
long maxZipSizeBytes = CxZipUtils.MAX_ZIP_SIZE_BYTES;
try (NewCxZipFile zipper = new NewCxZipFile(tempFile, maxZipSizeBytes, log)) {
zipper.addMultipleFilesToArchive(new File(sourceDir), paths);
if (zipper.getFileCount() == 0 && fingerprints.getFingerprints().isEmpty()) {
throw handleFileDeletion(tempFile);
}
if (!fingerprints.getFingerprints().isEmpty()) {
zipper.zipContentAsFile(FINGERPRINT_FILE_NAME, FingerprintCollector.getFingerprintsAsJsonString(fingerprints).getBytes());
} else {
log.debug("No supported fingerprints found to zip");
}
log.debug("The sources were zipped to {}", tempFile.getAbsolutePath());
return tempFile;
} catch (Zipper.MaxZipSizeReached e) {
throw handleFileDeletion(tempFile, new IOException("Reached maximum upload size limit of " + FileUtils.byteCountToDisplaySize(maxZipSizeBytes)));
} catch (IOException ioException) {
throw handleFileDeletion(tempFile, ioException);
}
}
Aggregations