1 16 package org.apache.juddi.uuidgen; 17 18 import java.io.BufferedReader ; 19 import java.io.IOException ; 20 import java.io.InputStreamReader ; 21 22 import org.apache.juddi.util.Config; 23 24 31 public final class NativeUUIDGen implements UUIDGen 32 { 33 private static final String COMMAND_KEY = "juddi.uuidgenCommand"; 34 private static final String DEFAULT_COMMAND = "uuidgen"; 35 private String command = null; 36 37 40 public NativeUUIDGen() 41 { 42 this.command = Config.getStringProperty(COMMAND_KEY,DEFAULT_COMMAND); 43 } 44 45 48 public String uuidgen() 49 { 50 try 51 { 52 Runtime r = Runtime.getRuntime(); 53 Process p = r.exec(command); 54 BufferedReader x = new BufferedReader ( 55 new InputStreamReader (p.getInputStream())); 56 57 return x.readLine(); 58 } 59 catch (IOException e) 60 { 61 e.printStackTrace(); 62 } 63 64 return null; 65 } 66 67 70 public String [] uuidgen(int nmbr) 71 { 72 String [] uuids = new String [nmbr]; 73 for (int i=0; i<uuids.length; i++) 74 uuids[i] = uuidgen(); 75 76 return uuids; 77 } 78 79 80 81 82 83 84 85 public static void main(String args[]) 86 { 87 UUIDGen generator = new NativeUUIDGen(); 88 long start = System.currentTimeMillis(); 89 90 for (int i = 1; i <= 100; ++i) 91 generator.uuidgen(); 92 93 long end = System.currentTimeMillis(); 94 95 System.out.println("\nNativeUUIDGen: Generation of 100 UUID's took " + 96 (end-start)+" milliseconds."); 97 } 98 } | Popular Tags |