List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, int repeat)
Repeat a String repeat
times to form a new String.
From source file:com.axelor.apps.admin.service.AsciiDocExportService.java
private String processMenu(String menu, FileWriter fw) throws IOException { hasMenu = true;/*from w w w . ja v a 2 s . c o m*/ String[] menus = menu.split("/", 4); int count = -1; String checkMenu = ""; for (String mn : menus) { count++; checkMenu += mn + "/"; if (!processedMenu.contains(checkMenu)) { fw.write("\n\n==" + StringUtils.repeat("=", count) + " " + mn); processedMenu.add(checkMenu); } } if (menuMap.containsKey(menu)) { fw.write("\n" + menuMap.get(menu)); } return menus[menus.length - 1]; }
From source file:dk.netarkivet.harvester.harvesting.MetadataFileWriterTester.java
/** * This is not run automatically, as this takes a long time to complete (15 seconds). * //from w ww . j a v a2 s. c o m * @throws IOException */ public void notestMetadataFileWriterWarcMassiveLoadTest() throws IOException { //TODO verify content of produced warc-file to ensure that all is OK File metafile = new File("metadata.warc"); MetadataFileWriter mdfw = MetadataFileWriterWarc.createWriter(metafile); ((MetadataFileWriterWarc) mdfw).insertInfoRecord(new ANVLRecord()); // Create 5000 small files String contentPart = "blablabla"; String someText = StringUtils.repeat(contentPart, 5000); List textArray = new ArrayList<String>(); textArray.add(someText); Set<File> files = new HashSet<File>(); for (int i = 0; i < 10000; i++) { File f = File.createTempFile("metadata", "cdx"); FileUtils.writeCollectionToFile(f, textArray); files.add(f); } System.out.println("Finished writing files"); int count = 0; for (File f : files) { mdfw.writeFileTo(f, "http://netarkivet/ressource-" + count, "text/plain"); f.delete(); count++; } metafile.delete(); System.out.println("Finished adding files to warc"); }
From source file:com.amazonaws.services.kinesis.producer.KinesisProducerTest.java
@Test public void rotatingCredentials() throws InterruptedException, ExecutionException { final String AKID_C = "AKIACCCCCCCCCCCCCCCC"; final String AKID_D = "AKIDDDDDDDDDDDDDDDDD"; final KinesisProducer kp = getProducer(new RotatingAwsCredentialsProvider( ImmutableList.<AWSCredentials>of(new BasicAWSCredentials(AKID_C, StringUtils.repeat("c", 40)), new BasicAWSCredentials(AKID_D, StringUtils.repeat("d", 40)))), null);/*from ww w . j av a2 s . co m*/ final long start = System.nanoTime(); while (System.nanoTime() - start < 500 * 1000000) { kp.addUserRecord("a", "a", ByteBuffer.wrap(new byte[0])); kp.flush(); Thread.sleep(10); } kp.flushSync(); kp.destroy(); Map<String, AtomicInteger> counts = new HashMap<String, AtomicInteger>(); counts.put(AKID_C, new AtomicInteger(0)); counts.put(AKID_D, new AtomicInteger(0)); for (ClientRequest cr : server.getRequests()) { String auth = cr.getHeaders().get("Authorization"); if (auth == null) { auth = cr.getHeaders().get("authorization"); } if (auth.contains(AKID_C)) { counts.get(AKID_C).getAndIncrement(); } else if (auth.contains(AKID_D)) { counts.get(AKID_D).getAndIncrement(); } else { fail("Expected AKID(s) not found in auth header"); } } assertTrue(counts.get(AKID_C).get() > 1); assertTrue(counts.get(AKID_D).get() > 1); }
From source file:com.megahardcore.config.messages.MessageConfig.java
/** * Set the header of the file before writing to it with bukkit yaml implementation * * @param file file to write the header to *//*from www . j a v a 2s.co m*/ private void setHeader(File file) { try { //Write header to a new file ByteArrayOutputStream memStream = new ByteArrayOutputStream(); OutputStreamWriter memWriter = new OutputStreamWriter(memStream, Charset.forName("UTF-8").newEncoder()); String[] header = { "Messages sent by MegaHardCore", "Messages are only sent for modules that are activated", "Modes (has to match exactly, ignores case)", "Disabled: Message won't be sent even if feature that would sent the message is active", "One_Time: Will be sent to every player only once", "Notification: Gets sent every time with a timeout to prevent spamming chat", "Tutorial: Sent a limited number of times and not displayed after 3 times", "Broadcast: Shown to whole server. Only few messages make sense to be broadcasted", "Variables:", "$ALLCAPS is a variable and will be filled in for some messages", "$PLAYER: Affected player", "$PLAYERS: If multiple players are affected", "$DEATH_MSG: Death message if someone dies", "$ITEMS: a player lost" }; StringBuilder sb = new StringBuilder(); sb.append(StringUtils.repeat("#", 100)); sb.append(System.lineSeparator()); for (String line : header) { sb.append('#'); sb.append(StringUtils.repeat(" ", 100 / 2 - line.length() / 2 - 1)); sb.append(line); sb.append(StringUtils.repeat(" ", 100 / 2 - line.length() / 2 - 1 - line.length() % 2)); sb.append('#'); sb.append(String.format(System.lineSeparator())); } sb.append(StringUtils.repeat("#", 100)); sb.append(String.format(System.lineSeparator())); //String.format: %n as platform independent line seperator memWriter.write(sb.toString()); memWriter.close(); IoHelper.writeHeader(file, memStream); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.extrahardmode.config.messages.MessageConfig.java
/** * Set the header of the file before writing to it with bukkit yaml implementation * * @param file file to write the header to *//*from w ww .j ava 2 s.co m*/ private void setHeader(File file) { try { //Write header to a new file ByteArrayOutputStream memStream = new ByteArrayOutputStream(); OutputStreamWriter memWriter = new OutputStreamWriter(memStream, Charset.forName("UTF-8").newEncoder()); String[] header = { "Messages sent by ExtraHardMode", "Messages are only sent for modules that are activated", "Modes (has to match exactly, ignores case)", "Disabled: Message won't be sent even if feature that would sent the message is active", "One_Time: Will be sent to every player only once", "Notification: Gets sent every time with a timeout to prevent spamming chat", "Tutorial: Sent a limited number of times and not displayed after 3 times", "Broadcast: Shown to whole server. Only few messages make sense to be broadcasted", "Variables:", "$ALLCAPS is a variable and will be filled in for some messages", "$PLAYER: Affected player", "$PLAYERS: If multiple players are affected", "$DEATH_MSG: Death message if someone dies", "$ITEMS: a player lost" }; StringBuilder sb = new StringBuilder(); sb.append(StringUtils.repeat("#", 100)); sb.append("%n"); for (String line : header) { sb.append('#'); sb.append(StringUtils.repeat(" ", 100 / 2 - line.length() / 2 - 1)); sb.append(line); sb.append(StringUtils.repeat(" ", 100 / 2 - line.length() / 2 - 1 - line.length() % 2)); sb.append('#'); sb.append(String.format("%n")); } sb.append(StringUtils.repeat("#", 100)); sb.append(String.format("%n")); //String.format: %n as platform independent line seperator memWriter.write(sb.toString()); memWriter.close(); IoHelper.writeHeader(file, memStream); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.sonyericsson.jenkins.plugins.bfa.tokens.Renderer.java
/** * @param indentLevel the indent level/*from w w w. ja v a 2 s . com*/ * @return a whitespace string with an appropriate with for the specified indent level */ static String indentForDepth(final int indentLevel) { return StringUtils.repeat(" ", indentLevel); }
From source file:aldenjava.opticalmapping.miscellaneous.ExtendOptionParser.java
@Override public void printHelpOn(OutputStream sink) { try {//from w ww . j a va 2 s. c o m NullHelpFormatter nhf = new NullHelpFormatter(); super.formatHelpWith(nhf); super.printHelpOn(new NullOutputStream()); if (recentparser != null) subParser.add(recentparser); recentparser = null; if (title != null) { sink.write((" " + title + "\n").getBytes()); sink.write((StringUtils.repeat("=", 60) + "\n").getBytes()); } for (int i = 0; i < header.size(); i++) { String separateLine = ""; String leftAdjust = StringUtils.repeat(" ", (level.get(i) - 1) * 2); if (level.get(i) == 1) separateLine = StringUtils.repeat("=", 10); else separateLine = StringUtils.repeat("-", 10); sink.write(("\n" + leftAdjust + separateLine + header.get(i) + separateLine + "\n").getBytes()); int elements = optionList.get(i).size(); leftAdjust = " " + leftAdjust; for (int j = 0; j < elements; j++) { String option = "--" + optionList.get(i).get(j); String description = optionDescriptionList.get(i).get(j); List<?> defaultValues = nhf.options.get(optionList.get(i).get(j)).defaultValues(); description += String.format(" [Default: %s]", defaultValues.size() == 1 ? defaultValues.get(0).toString() : defaultValues.size() == 0 ? "" : defaultValues.toString()); List<String> descriptionList = this.paragraphSeparate(description, 50); sink.write( (leftAdjust + String.format("%-25s%s\n", option, descriptionList.get(0))).getBytes()); for (int k = 1; k < descriptionList.size(); k++) sink.write( (leftAdjust + String.format("%-25s %s\n", "", descriptionList.get(k))).getBytes()); } // subParser.get(i).printHelpOn(sink); } } catch (IOException e) { System.err.println("IO Error. Help menu is not displayed successfully."); e.printStackTrace(); } }
From source file:fm.last.hadoop.tools.ReplicationPolicyFixer.java
private void findMissReplicatedFiles(FileStatus file, Set<Path> missReplicatedFiles) throws IOException { Path path = file.getPath();/*from www. j av a 2 s . c o m*/ if (file.isDir()) { FileStatus[] files = fs.listStatus(path); if (files == null) { return; } for (FileStatus subFile : files) { findMissReplicatedFiles(subFile, missReplicatedFiles); } return; } int pathNameLength = path.toUri().getPath().length(); String padding = StringUtils.repeat(" ", Math.max(0, lastPathNameLength - pathNameLength)); lastPathNameLength = pathNameLength; out.print(path.toUri().getPath() + padding + "\r"); out.flush(); LocatedBlocks blocks = nameNode.getBlockLocations(path.toUri().getPath(), 0, file.getLen()); if (blocks == null) { // the file is deleted return; } if (blocks.isUnderConstruction()) { out.println("\nNot checking open file : " + path.toString()); return; } for (LocatedBlock lBlk : blocks.getLocatedBlocks()) { if (lBlk.isCorrupt()) { out.println("\n" + lBlk.toString() + " is corrupt so skipping file : " + path.toString()); return; } Block block = lBlk.getBlock(); DatanodeInfo[] locs = lBlk.getLocations(); short targetFileReplication = file.getReplication(); // verify block placement policy int missingRacks = verifyBlockPlacement(lBlk, targetFileReplication, cluster); if (missingRacks > 0 && locs.length > 0) { out.println("\nReplica placement policy is violated for " + block.toString() + " of file " + path.toString() + ". Block should be additionally replicated on " + missingRacks + " more rack(s)."); missReplicatedFiles.add(path); } } }
From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSService.java
AmazonECSClient getAmazonECSClient() { final AmazonECSClient client; ProxyConfiguration proxy = Jenkins.getInstance().proxy; ClientConfiguration clientConfiguration = new ClientConfiguration(); if (proxy != null) { clientConfiguration.setProxyHost(proxy.name); clientConfiguration.setProxyPort(proxy.port); clientConfiguration.setProxyUsername(proxy.getUserName()); clientConfiguration.setProxyPassword(proxy.getPassword()); }//from w ww .j ava2 s . co m AmazonWebServicesCredentials credentials = getCredentials(credentialsId); if (credentials == null) { // no credentials provided, rely on com.amazonaws.auth.DefaultAWSCredentialsProviderChain // to use IAM Role define at the EC2 instance level ... client = new AmazonECSClient(clientConfiguration); } else { if (LOGGER.isLoggable(Level.FINE)) { String awsAccessKeyId = credentials.getCredentials().getAWSAccessKeyId(); String obfuscatedAccessKeyId = StringUtils.left(awsAccessKeyId, 4) + StringUtils.repeat("*", awsAccessKeyId.length() - (2 * 4)) + StringUtils.right(awsAccessKeyId, 4); LOGGER.log(Level.FINE, "Connect to Amazon ECS with IAM Access Key {1}", new Object[] { obfuscatedAccessKeyId }); } client = new AmazonECSClient(credentials, clientConfiguration); } client.setRegion(getRegion(regionName)); LOGGER.log(Level.FINE, "Selected Region: {0}", regionName); return client; }
From source file:com.evolveum.midpoint.repo.sql.util.MidpointPersisterUtil.java
private static void killUnwantedAssociationValues(String[] propertyNames, Type[] propertyTypes, Object[] values, int depth) { if (values == null) { return;/*from w ww. j a v a2 s . c o m*/ } for (int i = 0; i < propertyTypes.length; i++) { String name = propertyNames[i]; Type type = propertyTypes[i]; Object value = values[i]; if (LOGGER.isTraceEnabled()) { LOGGER.trace("{}- killUnwantedAssociationValues processing #{}: {} (type={}, value={})", StringUtils.repeat(" ", depth), i, name, type, value); } if (type instanceof ComponentType) { ComponentType componentType = (ComponentType) type; killUnwantedAssociationValues(componentType.getPropertyNames(), componentType.getSubtypes(), (Object[]) value, depth + 1); } else if (type instanceof ManyToOneType) { if (ASSOCIATION_TO_REMOVE.equals(name)) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("{}- killUnwantedAssociationValues KILLED #{}: {} (type={}, value={})", StringUtils.repeat(" ", depth), i, name, type, value); } values[i] = null; } } } }