1 21 22 package org.apache.derbyTesting.functionTests.harness; 23 24 import java.io.*; 25 26 30 public class UnJar 31 { 32 33 public UnJar() 34 { 35 } 36 37 public static void main(String args[]) throws Exception 38 { 39 UnJar uj = new UnJar(); 40 uj.unjar(args[0], null, true); 41 } 42 43 public static void unjar(String jarname, String outputdir, boolean useprocess) 44 throws ClassNotFoundException , IOException 45 { 46 if (outputdir == null) 47 outputdir = System.getProperty("user.dir"); 48 49 InputStream is = 50 RunTest.loadTestResource("upgrade" + '/' + jarname); 51 if (is == null) 52 { 53 System.out.println("File not found: " + jarname); 54 System.exit(1); 55 } 56 57 File jarFile = new File((new File(outputdir, jarname)).getCanonicalPath()); 60 FileOutputStream fos = new FileOutputStream(jarFile); 62 byte[] data = new byte[1024]; 63 int len; 64 while ((len = is.read(data)) != -1) 65 { 66 fos.write(data, 0, len); 67 } 68 fos.close(); 69 70 String jarCmd = "jar xf " + jarFile.getPath(); 72 if ( useprocess == true ) 73 { 74 Process pr = null; 76 try 77 { 78 pr = Runtime.getRuntime().exec(jarCmd); 80 81 pr.waitFor(); 82 pr.destroy(); 84 } 85 catch(Throwable t) 86 { 87 System.out.println("Process exception: " + t.getMessage()); 88 if (pr != null) 89 { 90 pr.destroy(); 91 pr = null; 92 } 93 } 94 } 95 else 96 { 97 System.out.println("Jar not implemented yet with useprocess=false"); 98 } 99 } 100 } 101 102 103 | Popular Tags |