62 |
private String namespace; |
private String namespace; |
63 |
private long nextNumber = 1; |
private long nextNumber = 1; |
64 |
|
|
65 |
public URN5Namespace() { |
/** Generate a sequence of base64 characters |
66 |
|
* with at least 160 bits of randomness. |
67 |
|
*/ |
68 |
|
public static synchronized String generateRandomChars() { |
69 |
if(sr == null) |
if(sr == null) |
70 |
sr = new SecureRandom(); |
sr = new SecureRandom(); |
71 |
|
|
72 |
namespace = ""; |
StringBuffer chars = new StringBuffer(NAMESPACECHARS); |
73 |
|
|
74 |
for(int i=0; i<NAMESPACECHARS; i++) { |
for(int i=0; i<NAMESPACECHARS; i++) { |
75 |
int x, n=0; |
int x, n=0; |
79 |
if(n > 1000) |
if(n > 1000) |
80 |
throw new Error("ARGH!"); |
throw new Error("ARGH!"); |
81 |
} while(x < 0 || x > 64); // step around a bug(?) in kaffe |
} while(x < 0 || x > 64); // step around a bug(?) in kaffe |
82 |
namespace = namespace + base64.charAt(x); |
chars.append(base64.charAt(x)); |
83 |
} |
} |
84 |
|
|
85 |
|
return chars.toString(); |
86 |
|
} |
87 |
|
|
88 |
|
public URN5Namespace() { |
89 |
|
namespace = generateRandomChars(); |
90 |
} |
} |
91 |
|
|
92 |
/** Get the base id of the namespace. |
/** Get the base id of the namespace. |