管道基础大数据平台系统开发-【后端】-Server
13693261870
2023-07-22 36d3d5d57ad24eecb09b7891e5dbd0d19977d82d
解决zip文件解压时遇到文件先于目录解压错误
已修改4个文件
82 ■■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/upload/UploadController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/all/StaticData.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/PathHelper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/ZipHelper.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/upload/UploadController.java
@@ -161,8 +161,8 @@
    @SysLog()
    @ApiOperation(value = "查询映射")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "20230110010101"),
            @ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query", example = "163"),
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "20230722"),
            @ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "verid", value = "版本ID", dataType = "Integer", paramType = "query", example = "0"),
            @ApiImplicitParam(name = "epsgCode", value = "坐标编码", dataType = "String", paramType = "query", example = "EPSG:4490")
    })
src/main/java/com/lf/server/entity/all/StaticData.java
@@ -30,7 +30,7 @@
    public final static int ONE_HUNDRED_THOUSAND = 100000;
    public static final double D75 = 75.0;
    public static final double D90 = 90.0;
    public static final double D100 = 100.0;
src/main/java/com/lf/server/helper/PathHelper.java
@@ -141,7 +141,7 @@
    public void deleteOldPath(String tempPath) {
        try {
            double ran = Math.random() * 99;
            if (ran < StaticData.D75) {
            if (ran < StaticData.D90) {
                return;
            }
src/main/java/com/lf/server/helper/ZipHelper.java
@@ -36,31 +36,9 @@
                dir.mkdirs();
            }
            int count;
            zipFile = new ZipFile(filePath, Charset.forName("GBK"));
            Enumeration e = zipFile.entries();
            while (e.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) e.nextElement();
                if (entry.isDirectory()) {
                    File f = new File(zipDir + File.separator + entry.getName());
                    if (!f.exists()) {
                        f.mkdirs();
                    }
                    continue;
                }
                BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));
                FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName());
                BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE);
                while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) {
                    dest.write(BUFFER, 0, count);
                }
                dest.flush();
                dest.close();
                fos.close();
                is.close();
            }
            createDirs(zipFile, zipDir);
            writeFiles(zipFile, zipDir);
            return true;
        } catch (Exception ex) {
@@ -78,6 +56,54 @@
    }
    /**
     * 创建目录
     */
    private static void createDirs(ZipFile zipFile, String zipDir) {
        Enumeration<?> e = zipFile.entries();
        while (e.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            if (entry.isDirectory()) {
                File f = new File(zipDir + File.separator + entry.getName());
                if (!f.exists()) {
                    f.mkdirs();
                }
            }
        }
    }
    /**
     * 写文件
     */
    private static void writeFiles(ZipFile zipFile, String zipDir) throws IOException {
        Enumeration<?> e = zipFile.entries();
        while (e.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            if (!entry.isDirectory()) {
                writeFile(zipFile, entry, zipDir);
            }
        }
    }
    /**
     * 写文件
     */
    private static void writeFile(ZipFile zipFile, ZipEntry entry, String zipDir) throws IOException {
        int count;
        BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));
        FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName());
        BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE);
        while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) {
            dest.write(BUFFER, 0, count);
        }
        dest.flush();
        dest.close();
        fos.close();
        is.close();
    }
    /**
     * Zip压缩
     *
     * @param zipFile   zip源文件