src/main/java/org/edgegallery/appstore/infrastructure/util/AppUtil.java
public void unzipApplicationPackage(String localFilePath, String intendedDir) {

        try (ZipFile zipFile = new ZipFile(localFilePath)) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            int entriesCount = 0;
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entriesCount > TOO_MANY) {
                    throw new AppException("too many files to unzip", ResponseConst.RET_UNZIP_TOO_MANY_FILES, TOO_MANY);
                }
                entriesCount++;
                // sanitize file path
                String fileName = LocalFileServiceImpl.sanitizeFileName(entry.getName(), intendedDir);
                if (!entry.isDirectory()) {
                    try (InputStream inputStream = zipFile.getInputStream(entry)) {
                        if (inputStream.available() > TOO_BIG) {
                            throw new AppException("file being unzipped is too big", ResponseConst.RET_FILE_TOO_BIG,
                                TOO_BIG);
                        }
                        FileUtils.copyInputStreamToFile(inputStream, new File(fileName));
                        LOGGER.info("unzip package... {}", entry.getName());
                    }
                } else {

                    File dir = new File(fileName);
                    boolean dirStatus = dir.mkdirs();
                    LOGGER.debug("creating dir {}, status {}", fileName, dirStatus);
                }
            }
        } catch (IOException e) {
            LOGGER.error("Failed to unzip");
            throw new AppException("Failed to unzip", ResponseConst.RET_DECOMPRESS_FAILED);
        }
    }
/**
     * Returns software image descriptor content in string format.
     *
     * @param localFilePath CSAR file path
     * @param intendedDir intended directory
     */
Returns software image descriptor content in string format.
@param localFilePath CSAR file path
@param intendedDir intended directory
Returns software image descriptor content in string format . @param localFilePath CSAR file path @param intendedDir intended directory
public void unzipApplicationPackage(String localFilePath, String intendedDir) {
        try (ZipFile zipFile = new ZipFile(localFilePath)) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            int entriesCount = 0;
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entriesCount > TOO_MANY) {
                    throw new AppException("too many files to unzip", ResponseConst.RET_UNZIP_TOO_MANY_FILES, TOO_MANY);
                }
                entriesCount++;
                String fileName = LocalFileServiceImpl.sanitizeFileName(entry.getName(), intendedDir);
                if (!entry.isDirectory()) {
                    try (InputStream inputStream = zipFile.getInputStream(entry)) {
                        if (inputStream.available() > TOO_BIG) {
                            throw new AppException("file being unzipped is too big", ResponseConst.RET_FILE_TOO_BIG,
                                TOO_BIG);
                        }
                        FileUtils.copyInputStreamToFile(inputStream, new File(fileName));
                        LOGGER.info("unzip package... {}", entry.getName());
                    }
                } else {
                    File dir = new File(fileName);
                    boolean dirStatus = dir.mkdirs();
                    LOGGER.debug("creating dir {}, status {}", fileName, dirStatus);
                }
            }
        } catch (IOException e) {
            LOGGER.error("Failed to unzip");
            throw new AppException("Failed to unzip", ResponseConst.RET_DECOMPRESS_FAILED);
        }
    }
public void unzipApplicationPackage ( String localFilePath , String intendedDir ) { try ( ZipFile zipFile = new ZipFile ( localFilePath ) ) { Enumeration < ? extends ZipEntry > entries = zipFile . entries ( ) ; int entriesCount = 0 ; while ( entries . hasMoreElements ( ) ) { ZipEntry entry = entries . nextElement ( ) ; if ( entriesCount > TOO_MANY ) { throw new AppException ( "too many files to unzip" , ResponseConst . RET_UNZIP_TOO_MANY_FILES , TOO_MANY ) ; } entriesCount ++ ; String fileName = LocalFileServiceImpl . sanitizeFileName ( entry . getName ( ) , intendedDir ) ; if ( ! entry . isDirectory ( ) ) { try ( InputStream inputStream = zipFile . getInputStream ( entry ) ) { if ( inputStream . available ( ) > TOO_BIG ) { throw new AppException ( "file being unzipped is too big" , ResponseConst . RET_FILE_TOO_BIG , TOO_BIG ) ; } FileUtils . copyInputStreamToFile ( inputStream , new File ( fileName ) ) ; LOGGER . info ( "unzip package... {}" , entry . getName ( ) ) ; } } else { File dir = new File ( fileName ) ; boolean dirStatus = dir . mkdirs ( ) ; LOGGER . debug ( "creating dir {}, status {}" , fileName , dirStatus ) ; } } } catch ( IOException e ) { LOGGER . error ( "Failed to unzip" ) ; throw new AppException ( "Failed to unzip" , ResponseConst . RET_DECOMPRESS_FAILED ) ; } }
Returns software image descriptor content in string format.
Returns software image descriptor content in string format .
// sanitize file path