Class StringToolkit


  • public final class StringToolkit
    extends Object
    A toolkit for strings.
    • Method Detail

      • readString

        public static String readString​(InputStream in)
                                 throws IOException
        Reads the contents of a stream to a string, assuming UTF-8 encoding.
        Parameters:
        in - the stream to read from
        Returns:
        a string with the contents available from the stream
        Throws:
        IOException - if something went wrong
      • readString

        public static String readString​(InputStream in,
                                        String charsetName)
                                 throws IOException
        Reads the contents of a stream with specified character encoding to a string.
        Parameters:
        in - the stream to read from
        charsetName - the name of a supported charset
        Returns:
        a string with the contents available from the stream
        Throws:
        IOException - if something went wrong
      • encodeFilename

        public static String encodeFilename​(String string)
        Encode a string so that it becomes safe to use as a file name.
        Parameters:
        string - string to encode
        Returns:
        a string usable as a file name
      • join

        public static String join​(Collection<?> s,
                                  String delimiter)
        Joins items in collection to one string with delimiter between each item.
        Parameters:
        s - collection of items
        delimiter - string to put between collection items
        Returns:
        a string joining all items in the collection with delimiter
      • join

        public static String join​(Object[] a,
                                  String delimiter)
        Joins items in an array to one string with delimiter between each item.
        Parameters:
        a - array of items
        delimiter - string to put between collection items
        Returns:
        a string joining all items in the array with delimiter