本文整理匯總了Java中org.apache.commons.lang3.RandomStringUtils.random方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomStringUtils.random方法的具體用法?Java RandomStringUtils.random怎麽用?Java RandomStringUtils.random使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang3.RandomStringUtils
的用法示例。
在下文中一共展示了RandomStringUtils.random方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shouldThrowAnExceptionIfRequestedTagIsNotFound
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
@Test
public void shouldThrowAnExceptionIfRequestedTagIsNotFound() throws Exception {
List<Node> testFixtures = nUnitAdapter.extractTestFixtures(nUnitAdapter.extractDocument(sample1Path));
NodeList nodeList = new NodeList() {
@Override
public Node item(int index) {
return testFixtures.get(0);
}
@Override
public int getLength() {
return 1;
}
};
String tagName = RandomStringUtils.random(5);
try {
nUnitAdapter.getNodesByTagName(nodeList, tagName);
fail("No exception was thrown");
} catch (Exception e) {
assertTrue(e.getMessage().equals("Element with tag name: " + tagName + " not found."));
}
}
示例2: shouldWriteConfigurationFile
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
@Test
public void shouldWriteConfigurationFile() throws IOException {
new ObjectMapper().writeValue(rewritableResourcePath.resolve("config.json").toFile(), defaultConfig);
try {
final JoalConfigProvider provider = new JoalConfigProvider(new ObjectMapper(), rewritableResourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class));
final Random rand = new Random();
final AppConfiguration newConf = new AppConfiguration(
rand.longs(1, 200).findFirst().getAsLong(),
rand.longs(201, 400).findFirst().getAsLong(),
rand.ints(1, 5).findFirst().getAsInt(),
RandomStringUtils.random(60),
false
);
provider.saveNewConf(newConf);
assertThat(provider.loadConfiguration()).isEqualTo(newConf);
} finally {
Files.deleteIfExists(rewritableResourcePath.resolve("config.json"));
}
}
示例3: register
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
@Transactional
public void register(RequestUserDTO userDTO, String requestURL) {
//ugly workaround to avoid concurrency issues
userRepository.findByUsernameOrEmail(userDTO.getUsername(), userDTO.getEmail())
.ifPresent(user -> {
throw new SBException("username or email already present in the system");
});
final String confirmationCode = RandomStringUtils.random(10, true, true);
User newUser = new User();
newUser.setEmail(userDTO.getEmail());
newUser.setUsername(userDTO.getUsername());
newUser.setPassword(passwordEncoder.encode(userDTO.getPassword()));
newUser.setConfirmationCode(confirmationCode);
newUser.setRole(Role.ROLE_USER);
//TODO - fix this url
String url = Utils.buildURL(requestURL, userDTO.getEmail(), confirmationCode);
emailSender.sendEmail(userDTO, url);
userRepository.save(newUser);
}
示例4: secureRandomAlphanumeric
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
/**
* Generate a random alphanumeric string using SecureRandom.
*
* @param length the length of the generated string
* @return a random string of the given length
* @see {@link SecureRandom}
*/
public static String secureRandomAlphanumeric(int length) {
return RandomStringUtils.random(
length,
0,
possibleCharacters.length - 1,
false,
false,
possibleCharacters,
new SecureRandom());
}
示例5: rename
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
/**
* 自定義方式重命名sql文件
* @param fileName 原文件名
* @return 新文件名(當前時間+4位隨機數+擴展名:201703091011581104.sql)
*/
public static String rename(String type) {
// 獲取4位隨機數字符串
String ranStr = RandomStringUtils.random(4, false, true);
// 當前時間字符串
String timeStr = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
return timeStr + ranStr + "." + type;
}
示例6: randomAsciiFixLength
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
/**
* 隨機ASCII字符(含字母,數字及其他符號),固定長度
*/
public static String randomAsciiFixLength(Random random, int length) {
return RandomStringUtils.random(length, 32, 127, false, false, null, random);
}
示例7: randomStringRandomLength
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
/**
* 隨機字母或數字,隨機長度
*/
public static String randomStringRandomLength(Random random, int minLength, int maxLength) {
return RandomStringUtils.random(nextInt(random, minLength, maxLength), 0, 0, true, true, null, random);
}
示例8: generateCommitterEmail
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
private String generateCommitterEmail() {
return RandomStringUtils.random(10, true, true) + "@redhat.com";
}
示例9: randomAsciiRandomLength
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
/**
* 隨機ASCII字符(含字母,數字及其他符號),隨機長度
*/
public static String randomAsciiRandomLength(Random random, int minLength, int maxLength) {
return RandomStringUtils.random(nextInt(random, minLength, maxLength), 32, 127, false, false, null, random);
}
示例10: randomAlphaNumericString
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
private String randomAlphaNumericString() {
int length = random.nextInt(10);
String alphanumerics = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
return RandomStringUtils.random(length, 0, alphanumerics.length(), true, true, alphanumerics.toCharArray(), random);
}
示例11: randomData
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
private String randomData() {
return RandomStringUtils.random(4096, "abcdefghijklmnopqrstuvwxyz");
}
示例12: registerUserIfNotExist
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
public String registerUserIfNotExist(User user)
{
String password = RandomStringUtils.random(10, "zvnjfsqw1234567890");
String query = "SELECT * FROM Users WHERE id = ?";
String insertQuery = "INSERT INTO Users (id, firstName, lastName, userName, language, isBot, password) " +
"VALUES (?, ?, ?, ?, ?, ?, ?) " +
"ON CONFLICT (id) DO UPDATE SET " +
"firstName = ?," +
"lastName =?," +
"userName = ?," +
"language = ?";
try
{
StringBuilder stringBuilder = new StringBuilder();
jdbcTemplate.query(query, result ->
{
String pas = result.getString("password");
if (pas != null)
{
stringBuilder.append(pas);
}
}, user.getId());
if (stringBuilder.length() == 0)
{
jdbcTemplate.update(insertQuery,
user.getId(),
user.getFirstName(),
user.getLastName(),
user.getUserName(),
user.getLanguageCode(),
user.getBot(),
password,
user.getFirstName(),
user.getLastName(),
user.getUserName(),
user.getLanguageCode()
);
return password;
}
}
catch (Exception e)
{
logger.error("Error", e);
}
return null;
}
示例13: generateClientId
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
public static String generateClientId(){
return RandomStringUtils.random(20,true,true);
}
示例14: generateClientSecret
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
public static String generateClientSecret(){
return RandomStringUtils.random(20, true, true);
}
示例15: randomLetterFixLength
import org.apache.commons.lang3.RandomStringUtils; //導入方法依賴的package包/類
/**
* 隨機字母,固定長度
*/
public static String randomLetterFixLength(Random random, int length) {
return RandomStringUtils.random(length, 0, 0, true, false, null, random);
}