public static String wrap(String line, final int widthInCharacters, String indent) {
    final StringBuilder buffer = new StringBuilder();

    int lineCount = 1;
    int spaceIndex;

    // if indent is null, then do not indent the wrapped lines
    indent = StringUtils.defaultString(indent);

    while (line.length() > widthInCharacters) {
      spaceIndex = line.substring(0, widthInCharacters).lastIndexOf(SPACE);
      buffer.append(lineCount++ > 1 ? indent : EMPTY);
      // throws IndexOutOfBoundsException if spaceIndex is -1, implying no word boundary was found
      // within
      // the given width; this also avoids the infinite loop
      buffer.append(line, 0, spaceIndex);
      buffer.append(LINE_SEPARATOR);
      // possible infinite loop if spaceIndex is -1, see comment above
      line = line.substring(spaceIndex + 1);
    }

    buffer.append(lineCount > 1 ? indent : "");
    buffer.append(line);

    return buffer.toString();
  }
Wraps a line of text to no longer than the specified width, measured by the number of
characters in each line, indenting all subsequent lines with the indent. If the indent is null,
then an empty String is used.
<p>

@param line a String containing the line of text to wrap.
@param widthInCharacters an integer value indicating the width of each line measured by the
       number of characters.
@param indent the String value used to indent all subsequent lines.
@return the line of text wrapped.
@throws IndexOutOfBoundsException if widthInCharacters is less than 0, or there are no word
        boundaries within the given width on any given split.
@throws NullPointerException if the line of text is null.
geode-core/src/main/java/org/apache/geode/internal/lang/StringUtils.java