MigrationFilePackOperation.jsp 4.07 KB
<%@ page import="weaver.general.GCONST" %><%@ page import="java.util.List" %><%@ page import="java.util.ArrayList" %><%@ page import="java.io.*" %><%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.json.JSONObject" %><% String rootpath=GCONST.getRootPath();
    new BaseBean().writeLog("开始打包文件");
    String filePath=rootpath+File.separatorChar+"system"+File.separatorChar+"upgradetoe9"+File.separatorChar+"report"+File.separatorChar+"migrationFile.txt";
    File file=new File(filePath);
    JSONObject jsonObject=new JSONObject();
    if(!file.exists() || !file.isFile()){//如果文件不存在的话,或则文件不是一个文件的话,不做任何操作
        new BaseBean().writeLog("迁移文件列表未找到");
        jsonObject.put("status","0");
        jsonObject.put("msg","迁移文件列表未找到");

    }else{
        new BaseBean().writeLog("打包文件找到");
        FileReader fr=new FileReader(file);
        BufferedReader  bufferedReader=new BufferedReader(fr);
        List<String>  pathlist=new ArrayList<String>();
        String str=null;
        while ((str=bufferedReader.readLine())!=null){
            new BaseBean().writeLog(rootpath+str);
            File file1=new File(rootpath+str);
            if(file1==null ||!file1.exists() || !file1.isFile()){
                new BaseBean().writeLog("打包文件未找到");
                continue;
            }
            pathlist.add(rootpath+str);
        }
        pathlist.add(filePath);
        if(bufferedReader!=null){
            bufferedReader.close();
        }
        if(fr!=null){
            fr.close();
        }
        wscheck.ZipUtils.execute(pathlist, GCONST.getRootPath()+"filesystem"+File.separatorChar+"scanecologyzip"+".zip",rootpath,"ecology");
        File allecologyzip = new File(GCONST.getRootPath()+"filesystem"+File.separatorChar+"scanecologyzip"+".zip");
        if(!allecologyzip.exists()){

            jsonObject.put("msg","文件未打包成功");
        }else{
            jsonObject.put("status","1");
        }
        response.getWriter().print(jsonObject.toString());
//        {
//            InputStream ins=null;
//            BufferedInputStream bins=null;
//            OutputStream outs=null;
//            BufferedOutputStream bouts=null;
//            try
//            {
//                response.reset();
//                ins=new FileInputStream(allecologyzip);
//                bins=new BufferedInputStream(ins);//放到缓冲流里面
//                outs=response.getOutputStream();//获取文件输出IO流
//                bouts=new BufferedOutputStream(outs);
//                response.setBufferSize(0);
//                response.setContentType("application/x-download");//设置response内容的类型
//                response.setHeader("Content-disposition","attachment;filename=\"scanecologyzip.zip");//设置头部信息
//                //response.addHeader("Content-Length", "" + newecologyzip.length());
//                int bytesRead = 0;
//                byte[] buffer = new byte[8192];
//                //开始向网络传输文件流
//                while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
//                    bouts.write(buffer, 0, bytesRead);
//                    bouts.flush();
//                }
//                bouts.flush();//这里一定要调用flush()方法
//                outs.flush();
//                ins.close();
//                bins.close();
//                outs.close();
//                bouts.close();
//                allecologyzip.delete();
//            }
//            catch (Exception ef)
//            {}
//            finally
//            {
//                if(ins!=null) ins.close();
//                if(bins!=null) bins.close();
//                if(outs!=null) outs.close();
//                if(bouts!=null) bouts.close();
//                if(bufferedReader!=null){
//                    bufferedReader.close();
//                }
//                if(fr!=null){
//                    fr.close();
//                }
//            }
//        }
    }
%>