< prev index next >

test/jdk/tools/pack200/Utils.java

Print this page
rev 50498 : 8199871: Deprecate pack200 and unpack200 tools
Reviewed-by:


 480         }
 481     }
 482 
 483     static ArrayList<String> getZipFileEntryNames(ZipFile z) {
 484         ArrayList<String> out = new ArrayList<String>();
 485         for (ZipEntry ze : Collections.list(z.entries())) {
 486             out.add(ze.getName());
 487         }
 488         return out;
 489     }
 490 
 491     static List<String> runExec(String... cmds) {
 492         return runExec(Arrays.asList(cmds));
 493     }
 494 
 495     static List<String> runExec(List<String> cmdsList) {
 496         return runExec(cmdsList, null);
 497     }
 498 
 499     static List<String> runExec(List<String> cmdsList, Map<String, String> penv) {




 500         ArrayList<String> alist = new ArrayList<String>();
 501         ProcessBuilder pb =
 502                 new ProcessBuilder(cmdsList);
 503         Map<String, String> env = pb.environment();
 504         if (penv != null && !penv.isEmpty()) {
 505             env.putAll(penv);
 506         }
 507         pb.directory(new File("."));
 508         dirlist(new File("."));
 509         for (String x : cmdsList) {
 510             System.out.print(x + " ");
 511         }
 512         System.out.println("");
 513         int retval = 0;
 514         Process p = null;
 515         InputStreamReader ir = null;
 516         BufferedReader rd = null;
 517         InputStream is = null;
 518         try {
 519             pb.redirectErrorStream(true);
 520             p = pb.start();
 521             is = p.getInputStream();
 522             ir = new InputStreamReader(is);
 523             rd = new BufferedReader(ir, 8192);
 524 
 525             String in = rd.readLine();
 526             while (in != null) {
 527                 alist.add(in);
 528                 System.out.println(in);
 529                 in = rd.readLine();
 530             }
 531             retval = p.waitFor();
 532             if (retval != 0) {
 533                 throw new RuntimeException("process failed with non-zero exit");
 534             }
 535         } catch (Exception ex) {
 536             throw new RuntimeException(ex.getMessage());
 537         } finally {
 538             close(rd);
 539             close(ir);
 540             close(is);
 541             if (p != null) {
 542                 p.destroy();
 543             }
 544         }
 545         return alist;
 546     }
 547 
 548     static String getUnpack200Cmd() {
 549         return getAjavaCmd("unpack200");
 550     }
 551 
 552     static String getPack200Cmd() {




 480         }
 481     }
 482 
 483     static ArrayList<String> getZipFileEntryNames(ZipFile z) {
 484         ArrayList<String> out = new ArrayList<String>();
 485         for (ZipEntry ze : Collections.list(z.entries())) {
 486             out.add(ze.getName());
 487         }
 488         return out;
 489     }
 490 
 491     static List<String> runExec(String... cmds) {
 492         return runExec(Arrays.asList(cmds));
 493     }
 494 
 495     static List<String> runExec(List<String> cmdsList) {
 496         return runExec(cmdsList, null);
 497     }
 498 
 499     static List<String> runExec(List<String> cmdsList, Map<String, String> penv) {
 500         return runExec(cmdsList, penv, false);
 501     }
 502 
 503     static List<String> runExec(List<String> cmdsList, Map<String, String> penv, boolean ignoreReturnValue) {
 504         ArrayList<String> alist = new ArrayList<String>();
 505         ProcessBuilder pb =
 506                 new ProcessBuilder(cmdsList);
 507         Map<String, String> env = pb.environment();
 508         if (penv != null && !penv.isEmpty()) {
 509             env.putAll(penv);
 510         }
 511         pb.directory(new File("."));
 512         dirlist(new File("."));
 513         for (String x : cmdsList) {
 514             System.out.print(x + " ");
 515         }
 516         System.out.println("");
 517         int retval = 0;
 518         Process p = null;
 519         InputStreamReader ir = null;
 520         BufferedReader rd = null;
 521         InputStream is = null;
 522         try {
 523             pb.redirectErrorStream(true);
 524             p = pb.start();
 525             is = p.getInputStream();
 526             ir = new InputStreamReader(is);
 527             rd = new BufferedReader(ir, 8192);
 528 
 529             String in = rd.readLine();
 530             while (in != null) {
 531                 alist.add(in);
 532                 System.out.println(in);
 533                 in = rd.readLine();
 534             }
 535             retval = p.waitFor();
 536             if (!ignoreReturnValue && retval != 0) {
 537                 throw new RuntimeException("process failed with non-zero exit");
 538             }
 539         } catch (Exception ex) {
 540             throw new RuntimeException(ex.getMessage());
 541         } finally {
 542             close(rd);
 543             close(ir);
 544             close(is);
 545             if (p != null) {
 546                 p.destroy();
 547             }
 548         }
 549         return alist;
 550     }
 551 
 552     static String getUnpack200Cmd() {
 553         return getAjavaCmd("unpack200");
 554     }
 555 
 556     static String getPack200Cmd() {


< prev index next >