|
2 | 2 |
|
3 | 3 | import com.xxl.job.core.context.XxlJobHelper; |
4 | 4 | import com.xxl.tool.core.ArrayTool; |
5 | | -import com.xxl.tool.core.AssertTool; |
6 | 5 | import com.xxl.tool.io.FileTool; |
| 6 | +import com.xxl.tool.io.IOTool; |
7 | 7 |
|
8 | | -import java.io.*; |
| 8 | +import java.io.FileOutputStream; |
| 9 | +import java.io.IOException; |
9 | 10 | import java.util.ArrayList; |
10 | 11 | import java.util.List; |
11 | 12 |
|
@@ -83,15 +84,15 @@ public static int execToFile(String command, String scriptFile, String logFile, |
83 | 84 | final FileOutputStream finalFileOutputStream = fileOutputStream; |
84 | 85 | inputThread = new Thread(() -> { |
85 | 86 | try { |
86 | | - copy(finalProcess.getInputStream(), finalFileOutputStream, true, false); |
| 87 | + // 数据流Copy(Input自动关闭,Output不处理) |
| 88 | + IOTool.copy(finalProcess.getInputStream(), finalFileOutputStream, true, false); |
87 | 89 | } catch (IOException e) { |
88 | 90 | XxlJobHelper.log(e); |
89 | 91 | } |
90 | 92 | }); |
91 | 93 | errorThread = new Thread(() -> { |
92 | 94 | try { |
93 | | - // 数据流Copy(Input自动关闭,Output不处理) |
94 | | - copy(finalProcess.getErrorStream(), finalFileOutputStream, true, false); |
| 95 | + IOTool.copy(finalProcess.getErrorStream(), finalFileOutputStream, true, false); |
95 | 96 | } catch (IOException e) { |
96 | 97 | XxlJobHelper.log(e); |
97 | 98 | } |
@@ -134,42 +135,6 @@ public static int execToFile(String command, String scriptFile, String logFile, |
134 | 135 | } |
135 | 136 | } |
136 | 137 |
|
137 | | - |
138 | | - private static final int BUFFER_SIZE = 1024 * 8; |
139 | | - private static int copy(InputStream input, OutputStream output, boolean closeInput, boolean closeOutput) throws IOException { |
140 | | - AssertTool.notNull(input, "No InputStream specified"); |
141 | | - AssertTool.notNull(output, "No OutputStream specified"); |
142 | | - |
143 | | - try { |
144 | | - int byteCount = 0; |
145 | | - byte[] buffer = new byte[BUFFER_SIZE]; |
146 | | - int bytesRead; |
147 | | - while ((bytesRead = input.read(buffer)) != -1) { |
148 | | - output.write(buffer, 0, bytesRead); |
149 | | - byteCount += bytesRead; |
150 | | - } |
151 | | - output.flush(); |
152 | | - return byteCount; |
153 | | - } finally { |
154 | | - if (closeInput) { |
155 | | - close(input); |
156 | | - } |
157 | | - if (closeOutput) { |
158 | | - close(output); |
159 | | - } |
160 | | - } |
161 | | - } |
162 | | - private static void close(Closeable closeable) { |
163 | | - if (closeable == null) { |
164 | | - return; |
165 | | - } |
166 | | - try { |
167 | | - closeable.close(); |
168 | | - } catch (IOException ex) { |
169 | | - // ignore |
170 | | - } |
171 | | - } |
172 | | - |
173 | 138 | /** |
174 | 139 | * 脚本执行,日志文件实时输出 |
175 | 140 | * |
|
0 commit comments