/** * <p>Wraps a single line of text, identifying words by <code>' '</code>.</p> * * <p>New lines will be separated by the system property line separator. * Very long words, such as URLs will <i>not</i> be wrapped.</p> * * <p>Leading spaces on a new line are stripped. * Trailing spaces are not stripped.</p> * * <pre> * WordUtils.wrap(null, *) = null * WordUtils.wrap("", *) = "" * </pre> * * @param str the String to be word wrapped, may be null * @param wrapLength the column to wrap the words at, less than 1 is treated as 1 * @return a line with newlines inserted, <code>null</code> if null input */ public static String wrap(String str, int wrapLength) { return wrap(str, wrapLength, null, false); }
/** * Format strings for command line output * * @param unformattedText * @param indentFirstLine * @param indentBalance * @return */ private String indentFormat( String unformattedText, int indentFirstLine, int indentBalance ) { final int maxWidth = 79; String leadLine = WordUtils.wrap( unformattedText, maxWidth - indentFirstLine ); StringBuilder result = new StringBuilder(); result.append( "\n" ); if ( leadLine.indexOf( NEW_LINE ) == -1 ) { result.append( NEW_LINE ).append( StringUtils.repeat( " ", indentFirstLine ) ).append( unformattedText ); } else { int lineBreakPoint = leadLine.indexOf( NEW_LINE ); String indentString = StringUtils.repeat( " ", indentBalance ); result.append( NEW_LINE ).append( StringUtils.repeat( " ", indentFirstLine ) ).append( leadLine.substring( 0, lineBreakPoint ) ); String formattedText = WordUtils.wrap( unformattedText.substring( lineBreakPoint ), maxWidth - indentBalance ); for ( String line : formattedText.split( NEW_LINE ) ) { result.append( NEW_LINE ).append( indentString ).append( line ); } } return result.toString(); }
String descr = "# " + WordUtils.wrap(opt.getDescription(), WRAP_COLUMNS, "\n# ", false); String dt = "# Data Type: "; if (opt.getDatatype().isArray()) { dt += opt.getDatatype().getSimpleName() + " enum:"; String s = "\n# " + "{ " + Joiner.on(", ").join(names) + " }"; dt += WordUtils.wrap(s, WRAP_COLUMNS, "\n# ", false); } else { dt += opt.getDatatype().getSimpleName(); "this file's copy of this setting is ignored. Use Titan's Management " + "System to read or modify this value after bootstrapping."; mut += WordUtils.wrap(warning, WRAP_COLUMNS, "\n# ", false);
String description = "# " + WordUtils.wrap(opt.getDescription(), WRAP_COLUMNS, "\n# ", false); String dt = "# Data Type: "; if (opt.getDatatype().isArray()) { dt += opt.getDatatype().getSimpleName() + " enum:"; String s = "\n# " + "{ " + Joiner.on(", ").join(names) + " }"; dt += WordUtils.wrap(s, WRAP_COLUMNS, "\n# ", false); } else { dt += opt.getDatatype().getSimpleName(); "this file's copy of this setting is ignored. Use JanusGraph's Management " + "System to read or modify this value after bootstrapping."; mut += WordUtils.wrap(warning, WRAP_COLUMNS, "\n# ", false);
/** * Wrap a line so it's no longer than a certain number of columns. * @param value String value to wrap * @param columns Maximum number of columns * @return Wrapped line, always non-null. */ public static String wrapLine(String value, int columns) { return WordUtils.wrap(value, columns); }
/** * Wrap a line so it's no longer than a certain number of columns. * @param value String value to wrap * @param columns Maximum number of columns * @param newline The newline string to use, like "\r\n" * @return Wrapped line, always non-null. */ public static String wrapLine(String value, int columns, String newline) { return WordUtils.wrap(value, columns, newline, true); }
private static String commentMultilineString(String commentPrefix, String multilineString) { String wrapped = WordUtils.wrap(multilineString, 80); return new BufferedReader(new StringReader(wrapped)) .lines().map(l -> WordUtils.wrap(l, 80)) .collect(Collectors.joining("\n" + commentPrefix, commentPrefix, "")); }
@Override public String getLongUsage() { return getShortUsage() + "\n" + WordUtils.wrap("Remove a cache pool. This also uncaches paths " + "associated with the pool.\n\n", AdminHelper.MAX_LINE_WIDTH) + "<name> Name of the cache pool to remove.\n"; }
private String prepTooltip(String description, boolean allowable, String versRange) { StringBuilder sb = new StringBuilder("<html>"); sb.append(WordUtils.wrap(description, TOOLTIP_WIDTH, "<br/>", false)); if (!allowable) { sb.append("<br/><i>").append(decodeVersRange(versRange)).append("</i>"); } return sb.toString(); }
/** * Displays the provided text wrapped nicely according to the default * terminal width. * @param text The text to be displayed. */ public static void wrapText(String text) { System.out.println(WordUtils.wrap(text, getWidth())); }
public String getWrappedValue() { if (wrappedString == null) wrappedString = WordUtils.wrap(value, cellProperties.getWrapLength(), "\n", true); return wrappedString; }
/** * @param prefix prepended to each line * @param multiline a long string to be wrapped across lines */ public void printLinesWrapped( String prefix, String multiline ) { multiline = multiline.replaceAll("[\\r\\n]",""); int availableWidth = console.getTerminal().getWidth() - prefix.length(); String wrapped = WordUtils.wrap(multiline, availableWidth); for( String line : wrapped.split("\\n") ) try { console.println(prefix+line); } catch( IOException e ) { throw new Error(e); } }
private String getExptInfoTable() { final Date dc = dateCompleted == null ? new Date() : dateCompleted; final List<String[]> data = new ArrayList<String[]>(); data.add(new String[] { "Class", exptClass.getName() }); data.add(new String[] { "Report compiled", new SimpleDateFormat().format(dc) }); if (experimentDetails != null) { data.add(new String[] { "Author", WordUtils.wrap(experimentDetails.author(), exptClass.getName().length()) }); data.add(new String[] { "Created on", experimentDetails.dateCreated() }); data.add(new String[] { "Description", WordUtils.wrap(experimentDetails.description(), exptClass.getName() .length()) }); } final ASCIITableHeader[] header = { new ASCIITableHeader("", ASCIITable.ALIGN_RIGHT), new ASCIITableHeader("", ASCIITable.ALIGN_LEFT) }; String table = ASCIITable.getInstance().getTable(header, data.toArray(new String[data.size()][])); final int width = table.indexOf("\n") + 1; table = table.substring(2 * width); return table; }
private String getExptInfoTable() { final Date dc = dateCompleted == null ? new Date() : dateCompleted; final List<String[]> data = new ArrayList<String[]>(); data.add(new String[] { "Class", exptClass.getName() }); data.add(new String[] { "Report compiled", new SimpleDateFormat().format(dc) }); if (experimentDetails != null) { data.add(new String[] { "Author", WordUtils.wrap(experimentDetails.author(), exptClass.getName().length()) }); data.add(new String[] { "Created on", experimentDetails.dateCreated() }); data.add(new String[] { "Description", WordUtils.wrap(experimentDetails.description(), exptClass.getName() .length()) }); } final ASCIITableHeader[] header = { new ASCIITableHeader("", ASCIITable.ALIGN_RIGHT), new ASCIITableHeader("", ASCIITable.ALIGN_LEFT) }; String table = ASCIITable.getInstance().getTable(header, data.toArray(new String[data.size()][])); final int width = table.indexOf("\n") + 1; table = table.substring(2 * width); return table; }
private String getBibliographyTable() { final ASCIITableHeader[] header = { new ASCIITableHeader("Bibliography", ASCIITable.ALIGN_LEFT) }; String refs = StandardFormatters.STRING.format(bibliography); refs = WordUtils.wrap(refs, Math.max(exptClass.getName().length() + 10, 72), SystemUtils.LINE_SEPARATOR + " ", true); final String[][] data = formatAsTable(refs); return ASCIITable.getInstance().getTable(header, data); }
private String getBibliographyTable() { final ASCIITableHeader[] header = { new ASCIITableHeader("Bibliography", ASCIITable.ALIGN_LEFT) }; String refs = StandardFormatters.STRING.format(bibliography); refs = WordUtils.wrap(refs, Math.max(exptClass.getName().length() + 10, 72), SystemUtils.LINE_SEPARATOR + " ", true); final String[][] data = formatAsTable(refs); return ASCIITable.getInstance().getTable(header, data); }
static void showScriptExceptionErrorMessage(ExecuteScriptException ex) { if (ex.getCause() instanceof SecurityException) { final String message = WordUtils.wrap(ex.getCause().getMessage(), 80, "\n ", false); UITools.errorMessage(TextUtils.format("ExecuteScriptSecurityError.text", message)); } else { final String message = WordUtils.wrap(ex.getMessage(), 80, "\n ", false); UITools.errorMessage(TextUtils.format("ExecuteScriptError.text", message)); } } }
private String prepareBodyForQuoted(MailMessage msg, String quotePrefix, String writtenBy) { quotePrefix += " "; DateFormat df = userSettingsHolder.getDateTimeFormat(); String body = quotePrefix + WordUtils.wrap(msg.getBody(), QUOTED_BODY_LINE_LENGTH, "\n", false).replaceAll("\n", "\n" + quotePrefix); String replyPrefix = "\n\n" + df.format(msg.getSendDate()) + " " + msg.getSender().getDisplayName() + " " + writtenBy + "\n"; return replyPrefix + body; }
@Override public String getLongUsage() { TableListing listing = AdminHelper.getOptionDescriptionListing(); listing.addRow("-stats", "Display additional cache pool statistics."); listing.addRow("<name>", "If specified, list only the named cache pool."); return getShortUsage() + "\n" + WordUtils.wrap("Display information about one or more cache pools, " + "e.g. name, owner, group, permissions, etc.", AdminHelper.MAX_LINE_WIDTH) + "\n\n" + listing.toString(); }
@Override public String getLongUsage() { TableListing listing = AdminHelper.getOptionDescriptionListing(); listing.addRow("<name>", "Name of the pool to modify."); listing.addRow("<owner>", "Username of the owner of the pool"); listing.addRow("<group>", "Groupname of the group of the pool."); listing.addRow("<mode>", "Unix-style permissions of the pool in octal."); listing.addRow("<limit>", "Maximum number of bytes that can be cached " + "by this pool."); listing.addRow("<maxTtl>", "The maximum allowed time-to-live for " + "directives being added to the pool."); return getShortUsage() + "\n" + WordUtils.wrap("Modifies the metadata of an existing cache pool. " + "See usage of " + AddCachePoolCommand.NAME + " for more details.", AdminHelper.MAX_LINE_WIDTH) + "\n\n" + listing.toString(); }