-<!--\r
-Copyright 2003-2004 The Apache Software Foundation.\r
- \r
-Licensed under the Apache License, Version 2.0 (the "License");\r
-you may not use this file except in compliance with the License.\r
-You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-Unless required by applicable law or agreed to in writing, software\r
-distributed under the License is distributed on an "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-See the License for the specific language governing permissions and\r
-limitations under the License.\r
--->\r
-<html>\r
- <body>\r
- Base64, Binary, and Hexadecimal String encoding and decoding.\r
- </body>\r
-</html>\r
+<!--
+Copyright 2003-2004 The Apache Software Foundation.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html>
+ <body>
+ Base64, Binary, and Hexadecimal String encoding and decoding.
+ </body>
+</html>
throw new IllegalArgumentException("checkedString is null");
}
- checkedString = checkedString.replaceAll("[\\\"]", "\\\\\"");
- checkedString = checkedString.replaceAll("[\n]", "\\\\\\\\n");
- this.checkedString = checkedString;
+ setCheckedString(checkedString);
}
/**
public void setCheckedString(String checkedString) {
checkedString = checkedString.replaceAll("[\\\"]", "\\\\\"");
checkedString = checkedString.replaceAll("[\n]", "\\\\\\\\n");
+ checkedString = checkedString.replaceAll("[/]", "_");
+ checkedString = checkedString.replaceAll("[\\+]", "-");
this.checkedString = checkedString;
}
*
* @return converted string
*/
+ @Override
public String toString() {
return checkedString;
}
package org.glite.jobid.api_java;
-import java.math.BigInteger;
import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Creates new instace of JobId with BK server address and port number, unique part
- * is generated
+ * is generated. If some exception is catched during generating the unique part, then
+ * System.exit(-1); is called.
*
* @param bkserver BK server address
* @param port BK server port
new Random().nextInt(999999);
digest.update(unique.getBytes(),0,unique.length());
- unique = new BigInteger(1,digest.digest()).toString(16);
+ Base64 base64 = new Base64();
+ byte[] tmp = base64.encode(digest.digest());
+ unique = new CheckedString(new String(tmp, 0, tmp.length-2)).toString();
} catch (NoSuchAlgorithmException ex) {
System.err.println(ex);
+ System.exit(-1);
}
-
- Base64 base64 = new Base64();
- byte[] tmp = base64.decode(unique.getBytes());
- boolean test = false;
- while(!test) {
- test = true;
- for (int i = 0; i < tmp.length; i++) {
- if (tmp[i] < 0) {
- tmp[i] = (byte)(-1*tmp[i]);
- test = false;
- }
- if (tmp[i] <= 47) {
- tmp[i] = (byte)(10+tmp[i]);
- test = false;
- }
- if (tmp[i] <= 64 && tmp[i] >= 58) {
- tmp[i] = (byte)(7+tmp[i]);
- test = false;
- }
- if (tmp[i] <= 96 && tmp[i] >= 91) {
- tmp[i] = (byte)(6+tmp[i]);
- test = false;
- }
- if (tmp[i] >= 123) {
- tmp[i] = (byte)(5-tmp[i]);
- test = false;
- }
- }
- }
- unique = new String(tmp);
}
/**