Class StringUtil

java.lang.Object
org.faktorips.util.StringUtil

public class StringUtil extends Object
A collection of utility methods for Strings.
  • Field Details

  • Method Details

    • readFromInputStream

      public static final String readFromInputStream(InputStream is, Charset charset) throws IOException
      Reads the available bytes from the input stream and returns them as a string using the given charset.

      This method closes the input stream before returning!

      Throws:
      IOException
    • readFromInputStream

      public static final String readFromInputStream(InputStream is, String charsetName) throws IOException
      Reads the available bytes from the input stream and returns them as a string using the given charset.

      This method closes the input stream before returning!

      Throws:
      IOException
    • unqualifiedName

      public static final String unqualifiedName(String qualifiedName)
      Takes a name like a class name and removes the package information from the beginning.
    • getPackageName

      public static final String getPackageName(String qualifiedClassName)
      Returns the package name for a given class name. Returns an empty String if the class name does not contain a package name.
      Throws:
      NullPointerException - if the qualifiedClassName is null.
    • getFilenameWithoutExtension

      public static String getFilenameWithoutExtension(String filename)
      Returns the filename without extension.
    • getFileExtension

      public static String getFileExtension(String fileName)
    • getInputStreamForString

      public static InputStream getInputStreamForString(String data, String charset) throws UnsupportedEncodingException
      Returns the input stream to read the given data.
      Parameters:
      data - The data to read.
      charset - The char set to be used to convert the string data to bytes.
      Throws:
      UnsupportedEncodingException - if the given char set is unsupported.
    • toCamelCase

      public static String toCamelCase(String text, boolean firstUp)
    • camelCaseToUnderscore

      public static String camelCaseToUnderscore(String text)
      Returns a String where an occurrence of a character followed by an upper case character is replaced by these characters divided by an underscore. Consecutive sequences of comma, dot, hyphen and whitespace is also replaced by one single underscore.

      For example:

        CamelCase      →  Camel_Case
        a.,- b-cdEF    →  a_b_cd_EF
       
    • camelCaseToUnderscore

      public static String camelCaseToUnderscore(String text, boolean splitUppercaseSequences)
      Returns a String where an occurrence of a character followed by an upper case character is replaced by these characters divided by an underscore. Consecutive sequences of comma, dot, hyphen and whitespace is also replaced by one single underscore.

      For example:

        CamelCase      →  Camel_Case
        a.,- b-cdEF    →  a_b_cd_E_F       (splitUppercaseSequences = true)
        a.,- b-cdEF    →  a_b_cd_EF       (splitUppercaseSequences = false)
       
    • getRangeString

      public static String getRangeString(int minValue, int maxValue)
      Returns a String of the form ' [x..y]', where x and y are the minimum and maximum values of a range. Note that maxValue will be represented as an asterisk (*) if its value is Integer.MAX_VALUE.
      Parameters:
      minValue - minimum value of the range.
      maxValue - maximum value of the range or Integer.MAX_VALUE to indicate an unbound range.
      Returns:
      a String representation of the range in the form ' [min..max]'.
    • getRangeString

      public static String getRangeString(int minValue, int maxValue, int defaultValue)
      Returns a String of the form ' [x..y, z]', where x and y are the minimum and maximum values of a range, and z is the default value of that range. Note that maxValue will be represented as an asterisk (*) if its value is Integer.MAX_VALUE.
      Parameters:
      minValue - minimum value of the range.
      maxValue - maximum value of the range or Integer.MAX_VALUE to indicate an unbound range.
      defaultValue - default value of the range (if showDefault is false, this value will be ignored).
      Returns:
      a String representation of the range in the form ' [min..max, default]'.
    • containsWhitespace

      public static boolean containsWhitespace(String string)
      Checks whether the String contains whitespace.
      Parameters:
      string - String to be checked
      Returns:
      true if the string contains whitespace, false if not