1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| public void zipFileAction(String computationDir,String email){ log.info("###### start zip file , computation is {} ###### ", computationDir); Process process = null; try {
ProcessBuilder pb = new ProcessBuilder(); pb.directory(new File(DirectoryUtil.getFileLocalAbsolutePathWithFileUrl("shell/action/"))); pb.command("chmod 777 " + shellProperties.getZipShellName()); pb.command("./"+shellProperties.getZipShellName() ,computationDir,shellProperties.getCompressedFileName()); pb.redirectErrorStream(true); process = pb.start(); writeToLocal(DirectoryUtil.getFileLocalAbsolutePathWithFileUrl(computationDir) + "/zipLog.txt",process.getInputStream());
} catch (IOException e) { log.error("###### run shell zip script is error , message is {}######", e.getMessage()); return; } int runningStatus = 0; try { runningStatus = process.waitFor(); } catch (InterruptedException e) { log.error("###### run shell zip script occurs error, error is {} ######", e.getMessage()); return; } if(runningStatus != 0) { log.error("###### run shell zip script failed.###### "); }else { log.info("###### run shell zip script success. ######"); } }
public String reader(InputStream input) { StringBuilder outDat = new StringBuilder(); try (InputStreamReader inputReader = new InputStreamReader(input, StandardCharsets.UTF_8); BufferedReader bufferedReader = new BufferedReader(inputReader)) { String line; while ((line = bufferedReader.readLine()) != null) { outDat.append(line); outDat.append("\n"); } } catch (IOException e) { log.error("exception is {}", e.getMessage()); } return outDat.toString(); }
private void writeToLocal(String destination, InputStream input) throws IOException { int index; byte[] bytes = new byte[1024]; FileOutputStream downloadFile = new FileOutputStream(destination); while ((index = input.read(bytes)) != -1) { downloadFile.write(bytes, 0, index); downloadFile.flush(); } downloadFile.close(); input.close(); }
|