workItem(TUP-21307):Duplicate code in IdGenerator + TalendString (#2193)

* workItem(TUP-21307):Duplicate code in IdGenerator + TalendString

https://jira.talendforge.org/browse/TUP-21307

* workItem(TUP-21307):Duplicate code in IdGenerator + TalendString

https://jira.talendforge.org/browse/TUP-21307

* workItem(TUP-21307):Use SecureRandom + StringBuilder in IdGenerator +
TalendString

https://jira.talendforge.org/browse/TUP-21307
This commit is contained in:
Tao Tao
2019-01-15 18:30:29 +08:00
committed by Zhiwei Xue
parent 331dd2e907
commit e5deedc9a8
2 changed files with 10 additions and 10 deletions

View File

@@ -5,7 +5,7 @@
// ============================================================================
package routines;
import java.util.Random;
import java.security.SecureRandom;
import java.util.Vector;
public class TalendString {
@@ -74,20 +74,20 @@ public class TalendString {
* {example} getAsciiRandomString(6) # Art34Z
*/
public static String getAsciiRandomString(int length) {
Random random = new Random();
SecureRandom random = new SecureRandom();
int cnt = 0;
StringBuffer buffer = new StringBuffer();
StringBuilder builder = new StringBuilder();
char ch;
int end = 'z' + 1;
int start = ' ';
while (cnt < length) {
ch = (char) (random.nextInt(end - start) + start);
if (Character.isLetterOrDigit(ch)) {
buffer.append(ch);
builder.append(ch);
cnt++;
}
}
return buffer.toString();
return builder.toString();
}
/**