Class StringManipulationHelper


  • public class StringManipulationHelper
    extends java.lang.Object
    A utility class for common String manipulation tasks. All functions are static methods.
    Author:
    Amr ALHOSSARY, Richard Adams
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String convertStreamToString​(java.io.InputStream stream)
      Converts an InputStream of text to a String, closing the stream before returning.
      static boolean equalsToIgnoreEndline​(java.lang.String expected, java.lang.String actual)
      Compares two strings in a case-sensitive manner for equality, line by line, ignoring any difference of end line delimiters contained within the 2 Strings.
      static boolean equalsToXml​(java.lang.String expected, java.lang.String actual)
      This method is not implemented or used, never returns true and should probably be removed.
      static java.lang.String join​(java.util.Collection<java.lang.String> s, java.lang.String delimiter)
      Joins Strings together with a delimiter to a single
      static java.lang.String padLeft​(java.lang.String s, int n)
      Adds padding to left of supplied string
      static java.lang.String padRight​(java.lang.String s, int n)
      Adds padding to right of supplied string
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • convertStreamToString

        public static java.lang.String convertStreamToString​(java.io.InputStream stream)
        Converts an InputStream of text to a String, closing the stream before returning.
        • Newlines are converted to Unix newlines (\n)
        • Default charset encoding is used to read the stream.
        • Any IOException reading the stream is 'squashed' and not made available to caller
        • An additional newline is appended at the end of the string.
          Parameters:
          stream -
          Returns:
          a possibly empty but non-null String
        • equalsToIgnoreEndline

          public static boolean equalsToIgnoreEndline​(java.lang.String expected,
                                                      java.lang.String actual)
          Compares two strings in a case-sensitive manner for equality, line by line, ignoring any difference of end line delimiters contained within the 2 Strings.
          This method should be used if and only if two Strings are considered identical when all nodes are identical including their relative order. Generally useful when asserting identity of automatically regenerated XML or PDB.
          Parameters:
          expected -
          actual -
        • equalsToXml

          public static boolean equalsToXml​(java.lang.String expected,
                                            java.lang.String actual)
          This method is not implemented or used, never returns true and should probably be removed.
          Parameters:
          expected -
          actual -
          Returns:
          Throws:
          java.lang.UnsupportedOperationException - in most cases
        • padLeft

          public static java.lang.String padLeft​(java.lang.String s,
                                                 int n)
          Adds padding to left of supplied string
          Parameters:
          s - The String to pad
          n - an integer >= 1
          Returns:
          The left-padded string.
          Throws:
          java.lang.IllegalArgumentException - if n <= 0
        • padRight

          public static java.lang.String padRight​(java.lang.String s,
                                                  int n)
          Adds padding to right of supplied string
          Parameters:
          s - The String to pad
          n - an integer >= 1
          Returns:
          The right-padded string.
          Throws:
          java.lang.IllegalArgumentException - if n <= 0
        • join

          public static java.lang.String join​(java.util.Collection<java.lang.String> s,
                                              java.lang.String delimiter)
          Joins Strings together with a delimiter to a single
          Parameters:
          s - An Iterable of Strings
          delimiter -
          Returns: