Package org.openjdk.jmc.common.util
Class StringToolkit
- java.lang.Object
-
- org.openjdk.jmc.common.util.StringToolkit
-
public final class StringToolkit extends Object
A toolkit for strings.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringencodeFilename(String string)Encode a string so that it becomes safe to use as a file name.static Stringjoin(Object[] a, String delimiter)Joins items in an array to one string with delimiter between each item.static Stringjoin(Collection<?> s, String delimiter)Joins items in collection to one string with delimiter between each item.static StringreadString(InputStream in)Reads the contents of a stream to a string, assuming UTF-8 encoding.static StringreadString(InputStream in, String charsetName)Reads the contents of a stream with specified character encoding to a string.
-
-
-
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 fromcharsetName- the name of a supportedcharset- 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 itemsdelimiter- string to put between collection items- Returns:
- a string joining all items in the collection with delimiter
-
-