in amazon-inspector-image-scanner/amazon-inspector-image-scanner-agent/src/main/java/com/amazon/inspector/teamcity/sbomgen/SbomgenDownloader.java [75:114]
private static String unzipFile(String zipPath) throws IOException {
String destinationPath = zipPath.replace(".zip", "");
byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipPath));
ZipEntry zipEntry = zis.getNextEntry();
String sbomgenPath = "";
while (zipEntry != null) {
File newFile = newFile(new File(destinationPath), zipEntry);
if (zipEntry.getName().endsWith("inspector-sbomgen")) {
sbomgenPath = newFile.getAbsolutePath();
newFile.setExecutable(true);
}
if (zipEntry.isDirectory()) {
if (!newFile.isDirectory() && !newFile.mkdirs()) {
throw new IOException("Failed to create directory " + newFile);
}
} else {
File parent = newFile.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
throw new IOException("Failed to create directory " + parent);
}
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
}
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
return sbomgenPath;
}