Class TruncatedString

java.lang.Object
io.jenkins.plugins.checks.api.TruncatedString

public class TruncatedString extends Object
Utility wrapper that silently truncates output with a message at a certain size.

The GitHub Checks API has a size limit on text fields. Because it also accepts markdown, it is not trivial to truncate to the required length as this could lead to unterminated syntax. The use of this class allows for adding chunks of complete markdown until an overflow is detected, at which point a message will be added and all future additions will be silently discarded.

  • Method Details

    • toString

      public String toString()
      Builds the string without truncation.
      Overrides:
      toString in class Object
      Returns:
      A string comprising the joined chunks.
    • build

      @Deprecated public String build(int maxSize)
      Deprecated.
      use the explicit buildByBytes(int) or buildByChars(int) method according to your requirements.
      Builds the string such that it does not exceed maxSize in bytes, including the truncation string.
      Parameters:
      maxSize - the maximum size of the resultant string.
      Returns:
      A string comprising as many of the joined chunks that will fit in the given size, plus the truncation string if truncation was necessary.
    • buildByBytes

      public String buildByBytes(int maxSize)
      Builds the string such that it does not exceed maxSize in bytes, including the truncation string.
      Parameters:
      maxSize - the maximum size of the resultant string.
      Returns:
      A string comprising as many of the joined chunks that will fit in the given size, plus the truncation string if truncation was necessary.
    • buildByChars

      public String buildByChars(int maxSize)
      Builds the string such that it does not exceed maxSize in chars, including the truncation string.
      Parameters:
      maxSize - the maximum size of the resultant string.
      Returns:
      A string comprising as many of the joined chunks that will fit in the given size, plus the truncation string if truncation was necessary.