1 17 package org.apache.forrest.eclipse.actions; 18 19 import java.io.BufferedReader ; 20 import java.io.File ; 21 import java.io.FileNotFoundException ; 22 import java.io.FilenameFilter ; 23 import java.io.IOException ; 24 import java.io.InputStreamReader ; 25 import java.net.Socket ; 26 import java.net.UnknownHostException ; 27 import java.util.ArrayList ; 28 import java.util.Arrays ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 36 public class Utilities { 37 38 43 static public List getFileListing(File directory) 44 throws FileNotFoundException { 45 class JARFilter implements FilenameFilter { 46 public boolean accept(File dir, String name) { 47 return (name.endsWith(".jar")); 48 } 49 } 50 51 List result = new ArrayList (); 52 File [] filesAndDirs = directory.listFiles(); 53 List filesDirs = Arrays.asList(filesAndDirs); 54 Iterator filesIter = filesDirs.iterator(); 55 File file = null; 56 57 while (filesIter.hasNext()) { 58 file = (File ) filesIter.next(); 59 60 if (!file.isFile()) { 61 List deeperList = getFileListing(file); 62 result.addAll(deeperList); 63 } else { 64 result.add(file); 65 } 66 } 67 68 return result; 69 } 70 71 75 static public boolean isPortFree(int portNumber) { 76 try { 77 Socket echoSocket = new Socket ("localhost", portNumber); 78 echoSocket.close(); 79 return false; 80 } catch (UnknownHostException e) { 81 return true; 82 83 } catch (IOException e) { 84 return true; 85 86 } 87 88 }; 89 90 93 static public void RunExtCommand(final String cmdString) { 94 Runnable r = new Runnable () { 95 public void run() { 96 Process p; 97 try { 98 System.out.println(cmdString); 99 p = Runtime.getRuntime().exec(cmdString); 100 101 BufferedReader br = new BufferedReader ( 102 new InputStreamReader (p.getInputStream())); 103 String str; 104 while ((str = br.readLine()) != null) 105 System.out.println(str); 106 107 p.waitFor(); 108 } catch (Exception e) { 109 System.out.println(e); 110 } 111 } 112 }; 113 r.run(); 114 } 115 } 116 | Popular Tags |