class StringUtilities {

    public static String addLineBreaks(String msg, int lineLength)
    {
        if (msg == null)
        {
            return null;
        }

        if (lineLength < 1)
        {
            return msg;
        }

        String msgCopy = msg;
        final StringBuilder sb = new StringBuilder();
        while (true)
        {
            int idx = msgCopy.indexOf(' ', lineLength);
            if (msgCopy.length() <= lineLength || idx <= 0)
            {
                sb.append(msgCopy);
                break;
            }
            final String tmp = msgCopy.substring(0, idx);
            sb.append(tmp).append(LINE_SEP);
            msgCopy = msgCopy.substring(++idx, msgCopy.length());
        }
        return sb.toString();
    }

    private  StringUtilities();

}