Code for adjusting linelength
I think your approach is fine, and it's easy to understand. I have just a few improvement ideas:


A more natural ordering of the method parameters might be: source, token, length, filler
Instead of Integer, int should be enough and shorter
Move the closure in collect to its own method
Do you really need the static final String declaration? Why not use simply def?
Do you really need the type declarations in the signature? You could omit them, and it will be still quite clear
The brackets around the multiplication are unnecessary in

line + (filler * (length - line.size()))



Suggested implementation

Putting the above suggestions together:

def adjustLineLength = { line, length, filler -&gt;
    if (line.size() &gt; length) {
        line.substring(0, length)
    } else if (line.size() &lt; length) {
        line + filler * (length - line.size())
    } else {
        line
    }
}

def adjustTextLength = { source, token, length, filler -&gt;
    source
    .tokenize(token)
    .collect { adjustLineLength(it, length, filler) }
    .join(token)
}