@@ -0,0 +1,2410 @@
+package org.xspring.tutorial.guava.pipe;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.function.Consumer;%0A%0A/**%0A * %3Cp%3ETitle: PipeDemo%3C/p%3E%0A * %3Cp%3EDescription: Function Description%3C/p%3E%0A * %3Cp%3ECopyright: Ruijie Co., Ltd. (c) 2018%3C/p%3E%0A * %3Cp%3E@Author: chenzhian%3C/p%3E%0A * %3Cp%3E@Date: 2018/4/12 14:31%3C/p%3E%0A */%0Apublic class PipeDemo %7B%0A%0A    private static class StreamGobbler implements Runnable %7B%0A        private InputStream inputStream;%0A%0A        private Consumer%3CString%3E consumer;%0A%0A        public StreamGobbler(InputStream inputStream, Consumer%3CString%3E consumer) %7B%0A            this.inputStream = inputStream;%0A            this.consumer = consumer;%0A        %7D%0A%0A        @Override%0A        public void run() %7B%0A            new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumer);%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        boolean needDestroy = (args == null %7C%7C args.length == 0 %7C%7C %221%22.equals(args%5B0%5D));%0A        Process process = null;%0A        try %7B%0A            boolean isWindows = System.getProperty(%22os.name%22).toLowerCase().startsWith(%22windows%22);%0A            String dirPath = System.getProperty(%22user.home%22);%0A            System.out.println(%22user.home=%22 + dirPath);%0A            String cmd = String.format(%22sh -c 'ls %25s'%22, dirPath);%0A            if (isWindows) %7B%0A                cmd = String.format(%22cmd.exe /c dir %25s%22, dirPath);%0A                System.out.println(%22cmd = %22 + cmd);%0A                process = Runtime.getRuntime().exec(cmd);%0A            %7D else %7B%0A                System.out.println(%22cmd = %22 + cmd);%0A                process = Runtime.getRuntime().exec(cmd);%0A            %7D%0A%0A            StreamGobbler streamGobbler = new StreamGobbler(process.getInputStream(), System.out::println);%0A            Executors.newSingleThreadExecutor().submit(streamGobbler);%0A            Thread.sleep(30000);%0A            System.out.println(%22Result:%22 + process.waitFor());%0A        %7D catch (IOException %7C InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D finally %7B%0A            if (process != null && needDestroy) %7B%0A                System.out.println(%22destroy process's resource!!%22);%0A                process.destroy();%0A            %7D else %7B%0A                System.out.println(%22NOT destroy process's resource!!%22);%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

add PipeDemo