管道基础大数据平台系统开发-【后端】-Server
13693261870
2022-10-20 41e661c57a6011a25c3aaf6647d20a03df7c17a3
添加zip包处理工具
已添加1个文件
已修改3个文件
140 ■■■■■ 文件已修改
data/menu-执行.xls 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/config/InitConfig.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/ZipHelper.java 130 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
说明.txt 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/menu-Ö´ÐÐ.xls
Binary files differ
src/main/java/com/lf/server/config/InitConfig.java
@@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lf.server.entity.bd.DlgAgnpEntity;
import com.lf.server.helper.PathHelper;
import com.lf.server.helper.ZipHelper;
import com.lf.server.mapper.bd.DlgAgnpMapper;
import com.lf.server.service.sys.ArgsService;
import org.apache.commons.logging.Log;
@@ -41,17 +42,19 @@
    public void run(ApplicationArguments args) {
        // noinspection AlibabaRemoveCommentedCode
        try {
            // "E:\\data\\7.Insar\\insartest.tif","E:\\data\\6.高光谱\\GF5_Cut_1.img","E:\\data\\22.tif\\110.747 sq km.tif","E:\\Test\\Test.gdb"
            // GDAL测试:"E:\\data\\7.Insar\\insartest.tif","E:\\data\\6.高光谱\\GF5_Cut_1.img","E:\\data\\22.tif\\110.747 sq km.tif","E:\\Test\\Test.gdb"
            //GdalHelper.readTif("E:\\data\\7.Insar\\insartest.tif")
            //GdalHelper.readShp("E:\\data\\13.cppe\\shps\\addr.shp");
            //GdalHelper.readGdb("E:\\Test\\addr.gdb");
            //com.lf.server.helper.RsaHelper.generate();
            //testMybatisPlus();
            pathHelper.init();
            //boolean f1 = ZipHelper.unzip("D:\\LF\\data\\resources.zip", "D:\\LF\\data\\unzip");
            boolean f2 = ZipHelper.zip("D:\\LF\\data\\res.zip", "D:\\LF\\data\\unzip\\resources");
            // åˆå§‹åŒ–
            pathHelper.init();
            argsService.initSettingData();
            log.info("***************** ç³»ç»Ÿå¯åŠ¨å®Œæ¯• *****************" + "\n");
src/main/java/com/lf/server/helper/ZipHelper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,130 @@
package com.lf.server.helper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
/**
 * Zip帮助类
 * @author WWW
 */
public class ZipHelper {
    private final static int BUFFER_SIZE = 1024;
    private final static byte[] BUFFER = new byte[1024];
    private final static Log log = LogFactory.getLog(ZipHelper.class);
    /**
     * è§£åŽ‹ç¼©
     *
     * @param filePath zip文件
     * @param zipDir   è§£åŽ‹è·¯å¾„
     * @return æˆåŠŸæ˜¯/否
     */
    public static boolean unzip(String filePath, String zipDir) {
        try {
            int count;
            ZipFile zipfile = new ZipFile(filePath);
            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();
                is.close();
            }
            return true;
        } catch (Exception ex) {
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
            return false;
        }
    }
    /**
     * Zip压缩
     *
     * @param zipFile   Zip源文件
     * @param sourceDir æºæ–‡ä»¶å¤¹
     * @return æˆåŠŸæ˜¯/否
     */
    public static boolean zip(String zipFile, String sourceDir) {
        ZipOutputStream zos = null;
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
            zos = new ZipOutputStream(fileOutputStream);
            File sourceFile = new File(sourceDir);
            compress(sourceFile, zos, sourceFile.getName());
            return true;
        } catch (Exception ex) {
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
            return false;
        } finally {
            try {
                if (zos != null) {
                    zos.close();
                }
            } catch (Exception e) {
                log.error(e.getMessage() + e.getStackTrace() + "\n");
            }
        }
    }
    /**
     * Zip压缩
     *
     * @param sourceFile Zip源文件
     * @param zos        Zip输出流
     * @param name       Zip文件名称
     * @throws Exception
     */
    public static void compress(File sourceFile, ZipOutputStream zos, String name) throws Exception {
        if (sourceFile.isFile()) {
            // å‘zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
            zos.putNextEntry(new ZipEntry(name));
            // copy文件到zip输出流中
            int len;
            FileInputStream in = new FileInputStream(sourceFile);
            while ((len = in.read(BUFFER)) != -1) {
                zos.write(BUFFER, 0, len);
            }
            zos.closeEntry();
            in.close();
        } else {
            File[] listFiles = sourceFile.listFiles();
            if (listFiles == null || listFiles.length == 0) {
                // ç©ºæ–‡ä»¶å¤¹çš„处理:没有文件,不需要文件的copy
                zos.putNextEntry(new ZipEntry(name + "/"));
                zos.closeEntry();
            } else {
                for (File file : listFiles) {
                    compress(file, zos, name + "/" + file.getName());
                }
            }
        }
    }
}
˵Ã÷.txt
@@ -22,6 +22,7 @@
.修改所有的批量新增、删除、修改接口
.开发大文件上传接口
.解决上传文件时实体类映射异常
.开发地名地址分页查询接口
-----------------------------------------------
1.上传文件(commons-fileupload) *