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:org.apache.hadoop.yarn.client.cli.TopCLI.java
private void setAppsHeader() { List<String> formattedStrings = new ArrayList<>(); for (EnumMap.Entry<Columns, ColumnInformation> entry : columnInformationEnumMap.entrySet()) { if (entry.getValue().display) { formattedStrings.add(String.format(entry.getValue().format, entry.getValue().header)); }/* w w w . jav a2s .c om*/ } appsHeader = StringUtils.join(formattedStrings.toArray(), " "); if (appsHeader.length() > terminalWidth) { appsHeader = appsHeader.substring(0, terminalWidth - System.lineSeparator().length()); } else { appsHeader += StringUtils.repeat(" ", terminalWidth - appsHeader.length() - System.lineSeparator().length()); } appsHeader += System.lineSeparator(); }
From source file:org.apache.hadoop.yarn.logaggregation.LogCLIHelpers.java
@Private public int dumpAllContainersLogs(ApplicationId appId, String appOwner, PrintStream out) throws IOException { Path remoteRootLogDir = new Path(getConf().get(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR)); String user = appOwner;/* www . ja v a 2 s. c o m*/ String logDirSuffix = LogAggregationUtils.getRemoteNodeLogDirSuffix(getConf()); // TODO Change this to get a list of files from the LAS. Path remoteAppLogDir = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir, appId, user, logDirSuffix); RemoteIterator<FileStatus> nodeFiles; try { Path qualifiedLogDir = FileContext.getFileContext(getConf()).makeQualified(remoteAppLogDir); nodeFiles = FileContext.getFileContext(qualifiedLogDir.toUri(), getConf()).listStatus(remoteAppLogDir); } catch (FileNotFoundException fnf) { logDirNotExist(remoteAppLogDir.toString()); return -1; } boolean foundAnyLogs = false; while (nodeFiles.hasNext()) { FileStatus thisNodeFile = nodeFiles.next(); if (thisNodeFile.getPath().getName().equals(appId + ".har")) { Path p = new Path("har:///" + thisNodeFile.getPath().toUri().getRawPath()); nodeFiles = HarFs.get(p.toUri(), conf).listStatusIterator(p); continue; } if (!thisNodeFile.getPath().getName().endsWith(LogAggregationUtils.TMP_FILE_SUFFIX)) { AggregatedLogFormat.LogReader reader = new AggregatedLogFormat.LogReader(getConf(), thisNodeFile.getPath()); try { DataInputStream valueStream; LogKey key = new LogKey(); valueStream = reader.next(key); while (valueStream != null) { String containerString = "\n\nContainer: " + key + " on " + thisNodeFile.getPath().getName(); out.println(containerString); out.println(StringUtils.repeat("=", containerString.length())); while (true) { try { LogReader.readAContainerLogsForALogType(valueStream, out, thisNodeFile.getModificationTime()); foundAnyLogs = true; } catch (EOFException eof) { break; } } // Next container key = new LogKey(); valueStream = reader.next(key); } } finally { reader.close(); } } } if (!foundAnyLogs) { emptyLogDir(remoteAppLogDir.toString()); return -1; } return 0; }
From source file:org.apache.hadoop.yarn.logaggregation.LogDumper.java
private int dumpAllContainersLogs(ApplicationId appId, String appOwner, PrintStream out) throws IOException { Path remoteRootLogDir = new Path(getConf().get(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR)); String user = appOwner;//from w ww . j a v a 2s .c o m String logDirSuffix = LogAggregationUtils.getRemoteNodeLogDirSuffix(getConf()); //TODO Change this to get a list of files from the LAS. Path remoteAppLogDir = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir, appId, user, logDirSuffix); RemoteIterator<FileStatus> nodeFiles; try { nodeFiles = FileContext.getFileContext().listStatus(remoteAppLogDir); } catch (FileNotFoundException fnf) { System.out.println("Logs not available at " + remoteAppLogDir.toString()); System.out.println("Log aggregation has not completed or is not enabled."); return -1; } while (nodeFiles.hasNext()) { FileStatus thisNodeFile = nodeFiles.next(); AggregatedLogFormat.LogReader reader = new AggregatedLogFormat.LogReader(getConf(), new Path(remoteAppLogDir, thisNodeFile.getPath().getName())); try { DataInputStream valueStream; LogKey key = new LogKey(); valueStream = reader.next(key); while (valueStream != null) { String containerString = "\n\nContainer: " + key + " on " + thisNodeFile.getPath().getName(); out.println(containerString); out.println(StringUtils.repeat("=", containerString.length())); while (true) { try { LogReader.readAContainerLogsForALogType(valueStream, out); } catch (EOFException eof) { break; } } // Next container key = new LogKey(); valueStream = reader.next(key); } } finally { reader.close(); } } return 0; }
From source file:org.apache.hadoop.yarn.nodelabels.TestCommonNodeLabelsManager.java
@Test(timeout = 5000) public void testAddInvalidlabel() throws IOException { boolean caught = false; try {/* w w w. j a va2 s . com*/ Set<String> set = new HashSet<String>(); set.add(null); mgr.addToCluserNodeLabelsWithDefaultExclusivity(set); } catch (IOException e) { caught = true; } Assert.assertTrue("null label should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of(CommonNodeLabelsManager.NO_LABEL)); } catch (IOException e) { caught = true; } Assert.assertTrue("empty label should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("-?")); } catch (IOException e) { caught = true; } Assert.assertTrue("invalid label charactor should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of(StringUtils.repeat("c", 257))); } catch (IOException e) { caught = true; } Assert.assertTrue("too long label should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("-aaabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot start with \"-\"", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("_aaabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot start with \"_\"", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("a^aabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot contains other chars like ^[] ...", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("aa[a]bbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot contains other chars like ^[] ...", caught); }
From source file:org.apache.hive.hplsql.functions.FunctionDatetime.java
public static Var currentTimestamp(int precision) { String format = "yyyy-MM-dd HH:mm:ss"; if (precision > 0 && precision <= 3) { format += "." + StringUtils.repeat("S", precision); }// w w w. ja v a 2 s .c om SimpleDateFormat f = new SimpleDateFormat(format); String s = f.format(Calendar.getInstance(TimeZone.getDefault()).getTime()); return new Var(Utils.toTimestamp(s), precision); }
From source file:org.apache.isis.profilestore.xml.internal.UserProfileContentWriter.java
private void writeOptions(final StringBuffer xml, final Options options, final String name1, final int level) { final String spaces = StringUtils.repeat(" ", level); final Iterator<String> names = options.names(); if (level == 0 || names.hasNext()) { xml.append(spaces + " <options"); if (name1 != null) { xml.append(" id=\"" + name1 + "\""); }/*from w w w. ja v a 2 s.c o m*/ xml.append(">\n"); while (names.hasNext()) { final String name = names.next(); if (options.isOptions(name)) { writeOptions(xml, options.getOptions(name), name, level + 1); } else { xml.append(spaces + " <option" + attribute("id", name) + ">" + options.getString(name) + "</option>\n"); } } xml.append(spaces + " </options>\n"); } }
From source file:org.apache.isis.viewer.scimpi.dispatcher.view.debug.Specification.java
private void specificationGraph(Request request, ObjectSpecification specification, String fieldName, List<ObjectSpecification> processed, int level) { if (processed.contains(specification)) { return;//from w ww.ja va 2s.co m } request.appendHtml(StringUtils.repeat(" ", level)); if (processed.contains(specification)) { request.appendHtml("* "); } request.appendHtml(specification.getFullIdentifier()); if (fieldName != null) { request.appendHtml(" (" + fieldName + ")"); } request.appendHtml("\n"); if (processed.contains(specification)) { return; } processed.add(specification); final List<ObjectAssociation> fields = specification.getAssociations(); for (int i = 0; i < fields.size(); i++) { ObjectSpecification fieldSpecification = fields.get(i).getSpecification(); if (fieldSpecification.isValue()) { continue; } specificationGraph(request, fieldSpecification, fields.get(i).getName(), processed, level + 1); } }
From source file:org.apache.james.jmap.utils.JsoupHtmlTextExtractor.java
private String convertNodeToText(HTMLNode htmlNode) { Node node = htmlNode.underlyingNode; if (node instanceof TextNode) { TextNode textNode = (TextNode) node; return textNode.getWholeText(); }//from w w w .j a v a 2 s . c o m if (node instanceof Element) { Element element = (Element) node; if (element.tagName().equals(BR_TAG)) { return "\n"; } if (isList(element)) { return convertListElement(htmlNode.listNestedLevel); } if (element.tagName().equals(OL_TAG)) { return "\n\n"; } if (element.tagName().equals(LI_TAG)) { return "\n" + StringUtils.repeat(" ", htmlNode.listNestedLevel) + "- "; } if (element.tagName().equals(P_TAG)) { return "\n\n"; } if (element.tagName().equals(IMG_TAG)) { return generateImageAlternativeText(element); } } return ""; }
From source file:org.apache.oodt.cas.cli.util.CmdLineUtils.java
/** * Formats given string to a string where txt starts at startIndex and wraps * around at endIndex, all other indexes are filled with empty space. *//* w w w. ja va2 s . com*/ public static String getFormattedString(String string, int startIndex, int endIndex) { StringBuilder outputString = new StringBuilder(""); String[] splitStrings = StringUtils.split(string, " "); StringBuffer curLine; for (int i = 0; i < splitStrings.length; i++) { curLine = new StringBuffer(""); curLine.append(splitStrings[i]).append(" "); for (; i + 1 < splitStrings.length && curLine.length() + splitStrings[i + 1].length() <= (endIndex - startIndex); i++) { curLine.append(splitStrings[i + 1]).append(" "); } outputString.append(StringUtils.repeat(" ", startIndex)).append(curLine.toString()).append("\n"); } return outputString.toString(); }
From source file:org.apache.openjpa.jdbc.meta.strats.AbstractLobTest.java
protected String createLobData() { return StringUtils.repeat("ooOOOOoo, ", 3000); }