List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric
public static String randomAlphanumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alpha-numeric characters.
From source file:com.boyuanitsm.fort.service.util.RandomUtil.java
/** * Generates a app key./* w w w . j a va 2s. c o m*/ * * @return the generated app key */ public static String generateAppKey() { return RandomStringUtils.randomAlphanumeric(APP_KEY_COUNT).toLowerCase(); }
From source file:it.iit.genomics.cru.bridges.liftover.ws.LiftOverRun.java
public static Mapping runLiftOver(String genome, String fromAssembly, String toAssembly, String chromosome, int start, int end) { String liftOverCommand = RESOURCE_BUNDLE.getString("liftOverCommand"); String liftOverPath = RESOURCE_BUNDLE.getString("liftOverPath"); String mapChainDir = RESOURCE_BUNDLE.getString("mapChainDir"); String tmpDir = RESOURCE_BUNDLE.getString("tmpDir"); Mapping mapping = null;/*from ww w . j av a2 s. c o m*/ Runtime r = Runtime.getRuntime(); String rootFilename = String.format("%s", RandomStringUtils.randomAlphanumeric(8)); String inputFilename = rootFilename + "-" + fromAssembly + ".bed"; String outputFilename = rootFilename + "-" + toAssembly + ".bed"; String unmappedFilename = rootFilename + "-" + "unmapped.bed"; String mapChain = fromAssembly.toLowerCase() + "To" + toAssembly.toUpperCase().charAt(0) + toAssembly.toLowerCase().substring(1) + ".over.chain.gz"; try { File tmpDirFile = new File(tmpDir); // if the directory does not exist, create it if (false == tmpDirFile.exists()) { System.out.println("creating directory: " + tmpDir); boolean result = tmpDirFile.mkdir(); if (result) { System.out.println("DIR created"); } } // Write input bed file File inputFile = new File(tmpDir + inputFilename); // if file doesnt exists, then create it if (!inputFile.exists()) { inputFile.createNewFile(); } FileWriter fw = new FileWriter(inputFile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(chromosome + "\t" + start + "\t" + end + "\n"); bw.close(); String commandArgs = String.format("%s %s %s %s %s", liftOverPath + "/" + liftOverCommand, tmpDir + inputFilename, mapChainDir + mapChain, tmpDir + outputFilename, tmpDir + unmappedFilename); System.out.println(commandArgs); Process p = r.exec(commandArgs); p.waitFor(); BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = b.readLine()) != null) { System.out.println(line); } b.close(); b = new BufferedReader(new FileReader(tmpDir + outputFilename)); while ((line = b.readLine()) != null) { String[] cells = line.split("\t"); String newChromosome = cells[0]; int newStart = Integer.parseInt(cells[1]); int newEnd = Integer.parseInt(cells[2]); mapping = new Mapping(genome, toAssembly, newChromosome, newStart, newEnd); } b.close(); // delete File delete = new File(tmpDir + inputFilename); delete.delete(); delete = new File(tmpDir + outputFilename); delete.delete(); delete = new File(tmpDir + unmappedFilename); delete.delete(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return mapping; }
From source file:com.adobe.acs.commons.util.ThreadContextClassLoaderTaskExecutorTest.java
@Test public void test_with_normal_execution() throws Exception { final String expectedResult = RandomStringUtils.randomAlphanumeric(10); final ClassLoader parent = getClass().getClassLoader(); final ClassLoader innerLoader = new DummyClassLoader(parent); //set the TCCL to something different ClassLoader outerLoader = new DummyClassLoader(parent); Thread.currentThread().setContextClassLoader(outerLoader); String actual = ThreadContextClassLoaderTaskExecutor.doWithTccl(innerLoader, new Callable<String>() { @Override//from ww w. jav a 2s . c o m public String call() throws Exception { assertEquals(innerLoader, Thread.currentThread().getContextClassLoader()); return expectedResult; } }); assertEquals(expectedResult, actual); assertEquals(outerLoader, Thread.currentThread().getContextClassLoader()); }
From source file:com.adobe.acs.commons.dam.DAMFunctionsTest.java
@Test public void testGetTitleOrName() { Asset assetWithTitle = mock(Asset.class); String title = RandomStringUtils.randomAlphanumeric(10); when(assetWithTitle.getMetadataValue(DamConstants.DC_TITLE)).thenReturn(title); assertEquals(title, DAMFunctions.getTitleOrName(assetWithTitle)); Asset assetWithoutTitle = mock(Asset.class); String name = RandomStringUtils.randomAlphanumeric(10); when(assetWithoutTitle.getName()).thenReturn(name); assertEquals(name, DAMFunctions.getTitleOrName(assetWithoutTitle)); verify(assetWithTitle, only()).getMetadataValue(DamConstants.DC_TITLE); verify(assetWithoutTitle).getMetadataValue(DamConstants.DC_TITLE); verify(assetWithoutTitle).getName(); verifyNoMoreInteractions(assetWithoutTitle); }
From source file:com.alibaba.dubbo.util.KetamaNodeLocatorTest.java
public static List<String> generateRandomStrings(final int size) { final List<String> results = new ArrayList<String>(size); for (int ix = 0; ix < size; ix++) { results.add(new StringBuilder(RandomStringUtils.randomAlphanumeric(5)) .append(RandomStringUtils.randomAlphabetic(ix % 5)).append(ix).toString()); }/* w w w .j av a2s.c o m*/ return results; }
From source file:com.davidoyeku.azure.practical.managment_demo.Vehicle.java
private String generateLicense() { return RandomStringUtils.randomAlphanumeric(4).toUpperCase(); }
From source file:guru.bubl.module.neo4j_user_repository.FriendManagerNeo4j.java
@Override public String add(User newFriend) { String confirmToken = RandomStringUtils.randomAlphanumeric(30); FriendStatus friendStatus = this.getStatusWithUser(newFriend); if (friendStatus == FriendStatus.waitingForYourAnswer) { this.confirm(newFriend); return null; }/*from w ww . j av a2 s.c o m*/ if (friendStatus != FriendStatus.none) { return null; } return NoEx.wrap(() -> { String query = String.format( "START user=node:node_auto_index('uri:%s') " + "with user " + "START otherUser=node:node_auto_index('uri:%s') " + "CREATE UNIQUE (user)-[friendship:friend]->(otherUser) " + "SET friendship.status='%s', " + "friendship.confirmToken='%s'", user.id(), newFriend.id(), FriendStatus.waiting, confirmToken); connection.createStatement().execute(query); return confirmToken; }).get(); }
From source file:de.hybris.platform.acceleratorservices.dataimport.batch.converter.RandomPasswordTranslator.java
@Override public void performImport(String cellValue, final Item processedItem) throws ImpExException { cellValue = (cellValue == null ? "" : cellValue.trim()) + RandomStringUtils.randomAlphanumeric(RANDOM_STRING_LENGTH); super.performImport(cellValue, processedItem); }
From source file:com.google.cloud.bigtable.hbase.DataGenerationHelper.java
public String randomString(String prefix, String suffix) { return prefix + RandomStringUtils.randomAlphanumeric(8) + suffix; }
From source file:edu.harvard.i2b2.oauth2.register.ejb.ClientManager.java
@PostConstruct public void newClient() { client = new Client(); client.setClientId(RandomStringUtils.randomAlphanumeric(20)); client.setClientSecret(RandomStringUtils.randomAlphanumeric(20)); }