code: public static String truncate (String str, int limit, String appendage)
      {
          if (str == null || str.length() <= limit) {
              return str;
          }
          return str.substring(0, limit - appendage.length()) + appendage;
      }
docs: Truncates the string so it has length less than or equal to the given limit. If truncation
  occurs, the result will end with the given appendage. Returns null if the input is null.