1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.uuidgen;
17
18 import java.io.IOException;
19 import java.io.BufferedReader;
20 import java.io.InputStreamReader;
21
22 /***
23 * Used to create new universally unique identifiers or UUID's (sometimes called
24 * GUID's). UDDI UUID's are allways formmated according to DCE UUID conventions.
25 *
26 * @author Steve Viens (sviens@apache.org)
27 */
28 public final class Win32UUIDGen implements UUIDGen
29 {
30 /***
31 *
32 */
33 public String uuidgen()
34 {
35 String[] uuids = this.uuidgen(1);
36 return uuids[0];
37 }
38
39 /***
40 *
41 */
42 public String[] uuidgen(int nmbr)
43 {
44 String[] uuids = new String[nmbr];
45
46 try
47 {
48 Runtime r = Runtime.getRuntime();
49 Process p = r.exec("uuidgen -n" + nmbr);
50 BufferedReader x = new BufferedReader(new InputStreamReader(p.getInputStream()));
51
52 for (int i = 0; i < nmbr; ++i)
53 uuids[i] = x.readLine();
54 }
55 catch (IOException ex)
56 {
57 ex.printStackTrace();
58 throw new RuntimeException(ex.getMessage());
59 }
60
61 return uuids;
62 }
63
64
65 /****************************************************************************/
66 /****************************** TEST DRIVER *********************************/
67 /****************************************************************************/
68
69
70 public static void main(String args[])
71 {
72 UUIDGen uuidgen = new Win32UUIDGen();
73
74 long start = System.currentTimeMillis();
75
76
77 for (int i = 1; i <= 250; ++i)
78 System.out.println( i + ": " + uuidgen.uuidgen());
79
80 long end = System.currentTimeMillis();
81
82 System.out.println("Generation (and display) of 250 UUID's took "+(end-start)+" milliseconds.");
83
84
85 start = System.currentTimeMillis();
86
87
88 String[] ids = uuidgen.uuidgen(250);
89 for (int i = 1; i < 250; ++i)
90 System.out.println( i + ": " + ids[i]);
91
92 end = System.currentTimeMillis();
93
94 System.out.println("Generation (and display) of 250 UUID's took "+(end-start)+" milliseconds.");
95 }
96 }