소스 검색

压缩场景 11

wuweihao 3 년 전
부모
커밋
be0556a271

+ 29 - 4
720yun_local_manage/gis_common/src/main/java/com/gis/common/util/CmdUtils.java

@@ -30,21 +30,46 @@ public class CmdUtils {
      * 调用算法 xx.sh 脚本
      * @param command
      */
-    public static void callSh(String command){
-        log.info("cmd: {}", command);
+//    public static void callSh(String command, Integer lineSize){
+//        log.info("cmd: {}", command);
+//        try {
+//            String[] cmd = new String[]{"/bin/sh", "-c", command};
+//            Process process = Runtime.getRuntime().exec(cmd);
+//            StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
+//            errorGobbler.start();
+//            StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
+//            outGobbler.start();
+//            process.waitFor();
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//    }
+
+    /**
+     *
+     * @param command 命令
+     * @param lineSize 日志输出行数 ,可以为null
+     */
+    public static void callShLine(String command, Integer lineSize){
+        log.info("cmd: " + command);
         try {
             String[] cmd = new String[]{"/bin/sh", "-c", command};
             Process process = Runtime.getRuntime().exec(cmd);
-            StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
+            log.info("开始运行");
+            StreamGobblerLine errorGobbler = new StreamGobblerLine(process.getErrorStream(), "ERROR");
             errorGobbler.start();
-            StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
+            // 200行打印一次日志
+            StreamGobblerLine outGobbler = new StreamGobblerLine(process.getInputStream(), "STDOUT", lineSize);
             outGobbler.start();
             process.waitFor();
         } catch (Exception e) {
             e.printStackTrace();
         }
+
     }
 
 
 
+
+
 }

+ 79 - 0
720yun_local_manage/gis_common/src/main/java/com/gis/common/util/StreamGobblerLine.java

@@ -0,0 +1,79 @@
+package com.gis.common.util;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.*;
+
+@Slf4j
+public class StreamGobblerLine extends Thread {
+
+	InputStream is;
+    String type;
+    OutputStream os;
+    Integer lineSize;  // 多少行打印日志一次
+
+    public StreamGobblerLine(InputStream is, String type) {
+        this(is, type, null, null);
+    }
+
+    public StreamGobblerLine(InputStream is, String type, Integer lineSize) {
+        this(is, type, null, lineSize);
+    }
+
+    StreamGobblerLine(InputStream is, String type, OutputStream redirect, Integer lineSize) {
+        this.is = is;  
+        this.type = type;  
+        this.os = redirect;
+        this.lineSize = lineSize;
+    }  
+
+    public void run() {
+        log.info("run StreamGobblerLine");
+
+        InputStreamReader isr = null;  
+        BufferedReader br = null;  
+        PrintWriter pw = null;  
+        try {  
+            if (os != null)  
+                pw = new PrintWriter(os);  
+
+            isr = new InputStreamReader(is);  
+            br = new BufferedReader(isr);  
+            String line=null;
+            int i = 1;
+            while ( (line = br.readLine()) != null) {
+                if (lineSize != null) {
+                    if (i % lineSize == 0) {
+                        log.info(type + "," + i +" : >" + line);
+                    }
+                } else {
+                    log.info(type + ","  + i +" : >" + line);
+                }
+                i++;
+
+            }
+
+            if (pw != null)  
+                pw.flush();  
+        } catch (IOException ioe) {  
+            ioe.printStackTrace();    
+        } finally{  
+            try {  
+            	if(pw!=null)
+            	{
+            		 pw.close();  
+            	}
+            	if(br!=null)
+            	{
+            		br.close();  
+            	}
+            	if(isr!=null)
+            	{
+            		isr.close();  
+            	}
+            } catch (IOException e) {  
+                e.printStackTrace();  
+            }  
+        }  
+    }  
+}

+ 2 - 2
720yun_local_manage/gis_pano/src/main/java/com/gis/cms/service/impl/OpsServiceImpl.java

@@ -61,7 +61,7 @@ public class OpsServiceImpl  implements OpsService {
         cmd = cmd.replaceAll("@workPace", configConstant.serverBasePath + "/work");
         cmd = cmd.replaceAll("@inDir", ids);
 
-        CmdUtils.callSh(cmd);
+        CmdUtils.callShLine(cmd, null);
 
         return Result.success(zipName);
     }
@@ -93,7 +93,7 @@ public class OpsServiceImpl  implements OpsService {
         cmd = cmd.replaceAll("@workPace", configConstant.serverBasePath );
         cmd = cmd.replaceAll("@inDir", dirCode);
 
-        CmdUtils.callSh(cmd);
+        CmdUtils.callShLine(cmd, 100);
 
 
         return Result.success(zipName);