当前位置: 首页>>代码示例>>Java>>正文


Java RandomStringUtils类代码示例

本文整理汇总了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;
    }
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:20,代码来源:ShareService.java

示例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;
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:27,代码来源:AppService.java

示例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;
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:21,代码来源:SessionService.java

示例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());
}
 
开发者ID:zhaoqicheng,项目名称:renren-fast,代码行数:17,代码来源:SysUserServiceImpl.java

示例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);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:22,代码来源:PropertyTypeConverterTest.java

示例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;
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:14,代码来源:DemoController.java

示例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;
	
}
 
开发者ID:tnscorcoran,项目名称:light-4-j-plugin-wrapper,代码行数:27,代码来源:UtilitiesServiceImpl.java

示例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;
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:20,代码来源:KalturaAPIService.java

示例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);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:23,代码来源:InviteServiceTest.java

示例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"));
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:21,代码来源:PersonServiceTest.java

示例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);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:20,代码来源:PersonServiceTest.java

示例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());
}
 
开发者ID:davichi11,项目名称:my-spring-boot-project,代码行数:17,代码来源:SysUserServiceImpl.java

示例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;
   }
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:17,代码来源:GZIPArchiveWriterTest.java

示例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;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:39,代码来源:HRegion.java


注:本文中的org.apache.commons.lang.RandomStringUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。