本文整理匯總了Java中org.apache.commons.lang.RandomStringUtils類的典型用法代碼示例。如果您正苦於以下問題:Java RandomStringUtils類的具體用法?Java RandomStringUtils怎麽用?Java RandomStringUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RandomStringUtils類屬於org.apache.commons.lang包,在下文中一共展示了RandomStringUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createShare
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
public Share createShare(HttpServletRequest request, List<MediaFile> files) throws Exception {
Share share = new Share();
share.setName(RandomStringUtils.random(5, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"));
share.setCreated(new Date());
share.setUsername(securityService.getCurrentUsername(request));
Calendar expires = Calendar.getInstance();
expires.add(Calendar.YEAR, 1);
share.setExpires(expires.getTime());
shareDao.createShare(share);
for (MediaFile file : files) {
shareDao.createSharedFiles(share.getId(), file.getPath());
}
LOG.info("Created share '" + share.getName() + "' with " + files.size() + " file(s).");
return share;
}
示例2: newApp
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
/**
* 創建新App對象
*
* @param name
* @param description
* @param admins
* @param developers
* @return
*/
private App newApp(String name, String description, String admins, String developers) {
Date now = new Date();
App app = new App();
// 設置名稱和描述
app.setName(name);
app.setDescription(description);
app.setAppKey(RandomStringUtils.randomAlphanumeric(18));
app.setAppSecret(RandomStringUtils.randomAlphanumeric(32));
app.setAdmins(admins);
app.setDevelopers(developers);
app.setCreator(UserContext.name());
app.setCreateTime(now);
return app;
}
示例3: createToken
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
/**
* 創建token
*
* @param email
*/
public String createToken(String email) {
String token = getToken(email);
if (StringUtils.isNotEmpty(token)) {
return token;
}
// 分配token
token = RandomStringUtils.randomAlphanumeric(32);
Session session = new Session();
session.setEmail(email);
session.setToken(token);
sessionMapper.insert(session);
return token;
}
示例4: save
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
@Override
@Transactional
public void save(SysUserEntity user) {
user.setCreateTime(new Date());
//sha256加密
String salt = RandomStringUtils.randomAlphanumeric(20);
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
user.setSalt(salt);
sysUserDao.save(user);
//檢查角色是否越權
checkRole(user);
//保存用戶與角色關係
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
}
示例5: testGetPersistentTypeForStrings
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
@Test
public void testGetPersistentTypeForStrings()
{
DefaultPropertyTypeConverter defaultPropertyTypeConverter = new DefaultPropertyTypeConverter();
// Check string.
PropertyValueEntity.PersistedType persistedType = PropertyValueEntity.getPersistedTypeEnum("test", defaultPropertyTypeConverter);
assertEquals(PropertyValueEntity.PersistedType.STRING, persistedType);
// String value with length greater than the DB supported threshold.
String stringValue = RandomStringUtils.randomAlphanumeric(2001);
// ... persisted as blobs (see MNT-17523 for details).
persistedType = PropertyValueEntity.getPersistedTypeEnum(stringValue, defaultPropertyTypeConverter);
assertEquals(PropertyValueEntity.PersistedType.SERIALIZABLE, persistedType);
// String value with length less than the DB supported threshold.
stringValue = RandomStringUtils.randomAlphanumeric(1999);
// ... persisted as strings
persistedType = PropertyValueEntity.getPersistedTypeEnum(stringValue, defaultPropertyTypeConverter);
assertEquals(PropertyValueEntity.PersistedType.STRING, persistedType);
}
示例6: findListIndividuLdapDemo
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
/**
* @return une liste de peopleLdap anonyme pour la recherche Ldap
*/
public List<PeopleLdap> findListIndividuLdapDemo(){
List<PeopleLdap> liste = new ArrayList<PeopleLdap>();
for (int i = 0;i<6;i++){
String login = RandomStringUtils.randomAlphabetic(8).toLowerCase()+RandomStringUtils.randomNumeric(1);
PeopleLdap people = new PeopleLdap(login,"displayName-"+login,"sn-"+login, "cn-"+login,
"mail-"+login, null,"M.", "givenName-"+login);
liste.add(people);
}
return liste;
}
示例7: createUnBindedSfcSecurityGroupMember
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
private static SecurityGroupMember createUnBindedSfcSecurityGroupMember(Set<VMPort> ports) {
VirtualizationConnector vc = mock(VirtualizationConnector.class);
when(vc.getControllerType()).thenReturn(NEUTRON_SFC_CONTROLLER);
SecurityGroup sg = mock(SecurityGroup.class);
when(sg.getVirtualizationConnector()).thenReturn(vc);
when(sg.getServiceFunctionChain()).thenReturn(mock(ServiceFunctionChain.class));
SecurityGroupMember sgm = mock(SecurityGroupMember.class);
when(sgm.getSecurityGroup()).thenReturn(sg);
when(sgm.getType()).thenReturn(SecurityGroupMemberType.values()[new Random().nextInt(2)]);
when(sgm.getMemberName()).thenReturn("member_" + RandomStringUtils.random(5));
when(sgm.getVmPorts()).thenReturn(ports);
when(sgm.getId()).thenReturn(SGM_ID);
return sgm;
}
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:18,代碼來源:SecurityGroupMemberHookCheckTaskTestData.java
示例8: createAccount
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
private String createAccount(int index) throws ServerError{
String email = props.getProperty("email-prefix") + RandomStringUtils.randomAlphanumeric(6)+props.getProperty("email-suffix");
// ********************** Signup Express (Account Create) **********************
String accountCreateURLPath = props.getProperty("account-create-url-path");
String accountCreateBody = props.getProperty("account-create-body");
accountCreateBody=accountCreateBody.replaceAll("<token>", props.getProperty("acccess-token"));
accountCreateBody=accountCreateBody.replaceAll("<org>", "Org-98");
accountCreateBody=accountCreateBody.replaceAll("<username>", email);
accountCreateBody=accountCreateBody.replaceAll("<email>", email);
accountCreateBody=accountCreateBody.replaceAll("<password>", props.getProperty("default-password"));
String fullurl = HOST+accountCreateURLPath;
HttpResponse resp = apiAccessor.post(fullurl, accountCreateBody);
String body = resp.getBody();
//TODO - Use a Jackson JSON to Object creator and get the id that way.
int indexOfStartOfId = body.indexOf("id\":") + 4;
int indexOfEndOfId = body.indexOf(",");
String accountId = body.substring(indexOfStartOfId, indexOfEndOfId);
return accountId;
}
示例9: makeSafePlaylistName
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
/**
* creates a playlist name that is <= 150 characters and is unique
*
* @param playlistName the name of the playlist
* @return the safe playlist name
* @throws IllegalArgumentException if playlist name is invalid
*/
@NoProfile
protected String makeSafePlaylistName(String playlistName) {
playlistName = StringUtils.trimToNull(playlistName);
if (playlistName == null) {
throw new IllegalArgumentException("playlistName cannot be null");
}
if (playlistName.length() > PLAYLIST_MAX_LENGTH) {
playlistName = StringUtils.abbreviate(playlistName, CATEGORY_MAX_LENGTH);
playlistName = playlistName.substring(0, CATEGORY_MAX_LENGTH-3) + RandomStringUtils.randomAlphanumeric(3);
}
return playlistName;
}
示例10: testStartInviteForSameInviteeButTwoDifferentSites
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
public void testStartInviteForSameInviteeButTwoDifferentSites()
throws Exception
{
final String inviteeUsername = INVITEE_FIRSTNAME + "_" + INVITEE_LASTNAME;
final String inviteeEmail = INVITEE_EMAIL_PREFIX + RandomStringUtils.randomAlphanumeric(6) + "@" + INVITEE_EMAIL_DOMAIN;
// Create person
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
createPerson(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeUsername, inviteeEmail);
return null;
}
}, AuthenticationUtil.getSystemUserName());
JSONObject result = startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmail, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_1,
Status.STATUS_CREATED);
startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmail, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_2, Status.STATUS_CREATED);
}
示例11: testUpdatePerson
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
public void testUpdatePerson() throws Exception
{
// Create a new person
String userName = RandomStringUtils.randomNumeric(6);
createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation",
"myJobTitle", "[email protected]", "myBio", "images/avatar.jpg", 0,
Status.STATUS_OK);
// Update the person's details
JSONObject result = updatePerson(userName, "updatedTitle", "updatedFirstName", "updatedLastName",
"updatedOrganisation", "updatedJobTitle", "[email protected]", "updatedBio",
"images/updatedAvatar.jpg", Status.STATUS_OK);
assertEquals(userName, result.get("userName"));
assertEquals("updatedFirstName", result.get("firstName"));
assertEquals("updatedLastName", result.get("lastName"));
assertEquals("updatedOrganisation", result.get("organization"));
assertEquals("updatedJobTitle", result.get("jobtitle"));
assertEquals("[email protected]", result.get("email"));
}
示例12: testCreatePerson
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
public void testCreatePerson() throws Exception
{
String userName = RandomStringUtils.randomNumeric(6);
// Create a new person
JSONObject result = createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation",
"myJobTitle", "[email protected]", "myBio", "images/avatar.jpg", 0,
Status.STATUS_OK);
assertEquals(userName, result.get("userName"));
assertEquals("myFirstName", result.get("firstName"));
assertEquals("myLastName", result.get("lastName"));
assertEquals("myOrganisation", result.get("organization"));
assertEquals("myJobTitle", result.get("jobtitle"));
assertEquals("[email protected]", result.get("email"));
// Check for duplicate names
createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation",
"myJobTitle", "myEmail", "myBio", "images/avatar.jpg", 0, 409);
}
示例13: save
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysUserEntity user) throws Exception {
user.setCreateTime(LocalDateTime.now());
//sha256加密
String salt = RandomStringUtils.randomAlphanumeric(20);
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
user.setSalt(salt);
sysUserDao.save(user);
//檢查角色是否越權
checkRole(user);
//保存用戶與角色關係
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
}
示例14: writeArchive
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
public static List<byte[]> writeArchive(final String path, final int n, final boolean randomized) throws IOException {
FileOutputStream fos = new FileOutputStream(path);
GZIPArchiveWriter gzaw = new GZIPArchiveWriter(fos);
GZIPArchive.WriteEntry we;
List<byte[]> contents = new ArrayList<>();
for (int i = 0; i < n; i++) {
we = gzaw.getEntry("Test " + i, "Comment " + i, new Date());
final byte[] content = Util.toByteArray(
randomized ? "MAGIC" + RandomStringUtils.randomAscii(1024 * (1 + i)) : "Hello, world " + i + "!\n");
we.deflater.write(content);
contents.add(content);
we.deflater.close();
}
gzaw.close();
return contents;
}
示例15: createHRegion
import org.apache.commons.lang.RandomStringUtils; //導入依賴的package包/類
/**
* Convenience method creating new HRegions. Used by createTable. The {@link WAL} for the created
* region needs to be closed explicitly, if it is not null. Use {@link HRegion#getWAL()} to get
* access.
*
* @param info Info for region to create.
* @param rootDir Root directory for HBase instance
* @param tableDir table directory
* @param wal shared WAL
* @param initialize - true to initialize the region
* @param ignoreWAL - true to skip generate new wal if it is null, mostly for createTable
* @return new HRegion
* @throws IOException
*/
public static HRegion createHRegion(final HRegionInfo info, final Path rootDir,
final Path tableDir, final Configuration conf, final HTableDescriptor hTableDescriptor,
final WAL wal, final boolean initialize, final boolean ignoreWAL) throws IOException {
LOG.info("creating HRegion " + info.getTable().getNameAsString() + " HTD == " + hTableDescriptor
+ " RootDir = " + rootDir + " Table name == " + info.getTable().getNameAsString());
FileSystem fs = FileSystem.get(conf);
HRegionFileSystem.createRegionOnFileSystem(conf, fs, tableDir, info);
WAL effectiveWAL = wal;
if (wal == null && !ignoreWAL) {
// TODO HBASE-11983 There'll be no roller for this wal?
// The WAL subsystem will use the default rootDir rather than the passed
// in rootDir
// unless I pass along via the conf.
Configuration confForWAL = new Configuration(conf);
confForWAL.set(HConstants.HBASE_DIR, rootDir.toString());
effectiveWAL = (new WALFactory(confForWAL,
Collections.<WALActionsListener>singletonList(new MetricsWAL()),
"hregion-" + RandomStringUtils.randomNumeric(8))).getWAL(info.getEncodedNameAsBytes());
}
HRegion region =
HRegion.newHRegion(tableDir, effectiveWAL, fs, conf, info, hTableDescriptor, null);
if (initialize) region.initialize(null);
return region;
}