src/main/java/org/edgegallery/appstore/infrastructure/util/AppUtil.java
public void updateJsonFile(SwImgDesc imageDesc, List<SwImgDesc> imgDecsLists, String fileParent, String imgPath) {
        int index = imgDecsLists.indexOf(imageDesc);
        String newPathName = "";
        try (ZipFile zipFile = new ZipFile(imgPath)) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.isDirectory()) {
                    continue;
                }
                newPathName = "Image/" + imgPath.substring(imgPath.lastIndexOf(File.separator) + 1)
                    + File.separator + entry.getName();
            }
        } catch (IOException e) {
            throw new AppException("failed to get image path from image file.",
                ResponseConst.RET_PARSE_FILE_EXCEPTION);
        }
        imageDesc.setSwImage(newPathName);
        imgDecsLists.set(index, imageDesc);
        String jsonFile = fileParent + File.separator + JSON_EXTENSION;
        File swImageDesc = new File(jsonFile);
        writeFile(swImageDesc, new Gson().toJson(imgDecsLists));
    }
/**
     * update json file.
     *
     * @param imageDesc imageDesc.
     * @param imgDecsLists imgDecsLists.
     * @param fileParent fileParent.
     * @param imgPath imgZipPath.
     */
update json file.
@param imageDesc imageDesc.
update json file . @param imageDesc imageDesc .
public void updateJsonFile(SwImgDesc imageDesc, List<SwImgDesc> imgDecsLists, String fileParent, String imgPath) {
        int index = imgDecsLists.indexOf(imageDesc);
        String newPathName = "";
        try (ZipFile zipFile = new ZipFile(imgPath)) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.isDirectory()) {
                    continue;
                }
                newPathName = "Image/" + imgPath.substring(imgPath.lastIndexOf(File.separator) + 1)
                    + File.separator + entry.getName();
            }
        } catch (IOException e) {
            throw new AppException("failed to get image path from image file.",
                ResponseConst.RET_PARSE_FILE_EXCEPTION);
        }
        imageDesc.setSwImage(newPathName);
        imgDecsLists.set(index, imageDesc);
        String jsonFile = fileParent + File.separator + JSON_EXTENSION;
        File swImageDesc = new File(jsonFile);
        writeFile(swImageDesc, new Gson().toJson(imgDecsLists));
    }
public void updateJsonFile ( SwImgDesc imageDesc , List < SwImgDesc > imgDecsLists , String fileParent , String imgPath ) { int index = imgDecsLists . indexOf ( imageDesc ) ; String newPathName = "" ; try ( ZipFile zipFile = new ZipFile ( imgPath ) ) { Enumeration < ? extends ZipEntry > entries = zipFile . entries ( ) ; while ( entries . hasMoreElements ( ) ) { ZipEntry entry = entries . nextElement ( ) ; if ( entry . isDirectory ( ) ) { continue ; } newPathName = "Image/" + imgPath . substring ( imgPath . lastIndexOf ( File . separator ) + 1 ) + File . separator + entry . getName ( ) ; } } catch ( IOException e ) { throw new AppException ( "failed to get image path from image file." , ResponseConst . RET_PARSE_FILE_EXCEPTION ) ; } imageDesc . setSwImage ( newPathName ) ; imgDecsLists . set ( index , imageDesc ) ; String jsonFile = fileParent + File . separator + JSON_EXTENSION ; File swImageDesc = new File ( jsonFile ) ; writeFile ( swImageDesc , new Gson ( ) . toJson ( imgDecsLists ) ) ; }
update json file.
update json file .