private static boolean isChangedFromZip()

in src/main/java/com/ecs/cicd/FileZipperHelper.java [42:74]


    private static boolean isChangedFromZip(String appspec,
                                            Path zipFile) throws IOException {
        if (Files.exists(zipFile)) {
            byte[] buffer = new byte[1024];
            InputStream inputStream = Files.newInputStream(zipFile);
            ZipInputStream zis = new ZipInputStream(inputStream);
            ZipEntry ze = zis.getNextEntry();
            while (ze != null) {
                String fileName = ze.getName();
                System.out.println("Unzipping file: " + fileName);
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    outputStream.write(buffer, 0, len);
                }

                String fileContentInZip = outputStream.toString(StandardCharsets.UTF_8);

                if (fileContentInZip.equals(appspec)) {
                    System.out.println("Skipped zipping of file again since the content is same as local zipped file in.");
                    return true;
                }

                outputStream.close();
                zis.closeEntry();
                ze = zis.getNextEntry();
            }
            zis.closeEntry();
            zis.close();
            inputStream.close();
        }
        return false;
    }