Java Utililty Methods String Indent Format

List of utility methods to do String Indent Format

Description

The list of methods to do String Indent Format are organized into topic(s).

Method

StringindentString(final int indentSpaces)
indent String
return SPACES.substring(0, Math.min(NO_OF_SPACES, indentSpaces));
StringindentString(int indent)
indent String
StringBuffer sbuf = new StringBuffer();
for (int i = 0; i < indent; i++)
    sbuf.append(" ");
return sbuf.toString();
StringindentString(int indent)
indent String
if (indent < 0) {
    return "";
return "                                                                              ".substring(0,
        indent);
StringindentString(String s, char open, char middle, char close)
To be used with (open,middle,close)=('[',',',']') for the output of ToStringBuilder.reflectionToString
StringBuilder b = new StringBuilder();
int level = 0;
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (c == open) {
        b.append(c);
        b.append("\n");
        ++level;
...
StringindentString(String str, String indent)
indent String
StringBuilder sb = new StringBuilder(indent);
for (int i = 0; i < str.length(); i++) {
    char ch = str.charAt(i);
    sb.append(ch);
    if (ch == '\n' && i != str.length() - 1) {
        sb.append(indent);
return sb.toString();
voidindentStringBuffer(StringBuffer sb, int indent)
add indent to a StringBuffer
sb.append(indentString(indent));
StringindentText(String text, boolean indentFirstLine)
Adds an indentation before every line (optionally the first line can be an exception) of the given string.
String result = text != null ? text.replace("\n", "\n" + INDENTATION) : NULL_STR;
return indentFirstLine ? (INDENTATION + result) : result;
StringindentTransform(String in, int indent)
add indent to a String
StringBuffer sb = new StringBuffer(in.length() + 64 * indent);
String IndentString = indentString(indent);
for (int i = 0; i < in.length(); i++) {
    char c = in.charAt(i);
    switch (c) {
    case '\n':
        sb.append(c);
        if (i < (in.length() - 1))
...
voidindentWith(String s)
indent With
indentStr = indentStr + s;