Class StringBuilders

java.lang.Object
org.apache.logging.log4j.util.StringBuilders

@InternalApi public final class StringBuilders extends Object
Consider this class private.
Since:
2.3
  • Field Details

    • REPLACEMENT_CHAR

      private static final char REPLACEMENT_CHAR
      See Also:
    • timeClass

      private static final Class<?> timeClass
    • dateClass

      private static final Class<?> dateClass
  • Constructor Details

    • StringBuilders

      private StringBuilders()
  • Method Details

    • appendDqValue

      public static StringBuilder appendDqValue(StringBuilder sb, Object value)
      Appends in the following format: double quoted value.
      Parameters:
      sb - a string builder
      value - a value
      Returns:
      "value"
    • appendKeyDqValue

      public static StringBuilder appendKeyDqValue(StringBuilder sb, Map.Entry<String,String> entry)
      Appends in the following format: key=double quoted value.
      Parameters:
      sb - a string builder
      entry - a map entry
      Returns:
      key="value"
    • appendKeyDqValue

      public static StringBuilder appendKeyDqValue(StringBuilder sb, String key, Object value)
      Appends in the following format: key=double quoted value.
      Parameters:
      sb - a string builder
      key - a key
      value - a value
      Returns:
      the specified StringBuilder
    • appendValue

      public static void appendValue(StringBuilder stringBuilder, Object obj)
      Appends a text representation of the specified object to the specified StringBuilder, if possible without allocating temporary objects.
      Parameters:
      stringBuilder - the StringBuilder to append the value to
      obj - the object whose text representation to append to the StringBuilder
      Since:
      2.7
    • appendSpecificTypes

      public static boolean appendSpecificTypes(StringBuilder stringBuilder, Object obj)
      Since:
      2.10.0
    • isTime

      private static boolean isTime(Object obj)
    • isDate

      private static boolean isDate(Object obj)
    • equals

      public static boolean equals(CharSequence left, int leftOffset, int leftLength, CharSequence right, int rightOffset, int rightLength)
      Returns true if the specified section of the left CharSequence equals the specified section of the right CharSequence.
      Parameters:
      left - the left CharSequence
      leftOffset - start index in the left CharSequence
      leftLength - length of the section in the left CharSequence
      right - the right CharSequence to compare a section of
      rightOffset - start index in the right CharSequence
      rightLength - length of the section in the right CharSequence
      Returns:
      true if equal, false otherwise
      Since:
      2.8
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(CharSequence left, int leftOffset, int leftLength, CharSequence right, int rightOffset, int rightLength)
      Returns true if the specified section of the left CharSequence equals, ignoring case, the specified section of the right CharSequence.
      Parameters:
      left - the left CharSequence
      leftOffset - start index in the left CharSequence
      leftLength - length of the section in the left CharSequence
      right - the right CharSequence to compare a section of
      rightOffset - start index in the right CharSequence
      rightLength - length of the section in the right CharSequence
      Returns:
      true if equal ignoring case, false otherwise
      Since:
      2.8
    • trimToMaxSize

      public static void trimToMaxSize(StringBuilder stringBuilder, int maxSize)
      Ensures that the char[] array of the specified StringBuilder does not exceed the specified number of characters. This method is useful to ensure that excessively long char[] arrays are not kept in memory forever.
      Parameters:
      stringBuilder - the StringBuilder to check
      maxSize - the maximum number of characters the StringBuilder is allowed to have
      Since:
      2.9.0
    • escapeJson

      public static void escapeJson(StringBuilder toAppendTo, int start)
      Since:
      2.10.0
    • escapeAndDecrement

      private static int escapeAndDecrement(StringBuilder toAppendTo, int lastPos, char c)
    • escapeXml

      public static void escapeXml(StringBuilder toAppendTo, int start)
      Since:
      2.10.0
    • isValidXml10

      private static boolean isValidXml10(char ch)
      Checks if a BMP char is a valid XML 1.0 character.

      This method is restricted to characters in the BMP, i.e. represented by one UTF-16 code unit.

      Parameters:
      ch - a BMP char to validate
      Returns:
      true if it is a valid XML 1.0 character