Package org.openjdk.jmc.common.util
Class StringToolkit
- java.lang.Object
-
- org.openjdk.jmc.common.util.StringToolkit
-
public final class StringToolkit extends java.lang.ObjectA toolkit for strings.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringUTF_8
-
Constructor Summary
Constructors Modifier Constructor Description privateStringToolkit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringencodeFilename(java.lang.String string)Encode a string so that it becomes safe to use as a file name.static java.lang.Stringjoin(java.lang.Object[] a, java.lang.String delimiter)Joins items in an array to one string with delimiter between each item.static java.lang.Stringjoin(java.util.Collection<?> s, java.lang.String delimiter)Joins items in collection to one string with delimiter between each item.static java.lang.StringreadString(java.io.InputStream in)Reads the contents of a stream to a string, assuming UTF-8 encoding.static java.lang.StringreadString(java.io.InputStream in, java.lang.String charsetName)Reads the contents of a stream with specified character encoding to a string.
-
-
-
Field Detail
-
UTF_8
private static final java.lang.String UTF_8
- See Also:
- Constant Field Values
-
-
Method Detail
-
readString
public static java.lang.String readString(java.io.InputStream in) throws java.io.IOExceptionReads 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:
java.io.IOException- if something went wrong
-
readString
public static java.lang.String readString(java.io.InputStream in, java.lang.String charsetName) throws java.io.IOExceptionReads 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:
java.io.IOException- if something went wrong
-
encodeFilename
public static java.lang.String encodeFilename(java.lang.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 java.lang.String join(java.util.Collection<?> s, java.lang.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
-
join
public static java.lang.String join(java.lang.Object[] a, java.lang.String delimiter)Joins items in an array to one string with delimiter between each item.- Parameters:
a- array of itemsdelimiter- string to put between collection items- Returns:
- a string joining all items in the array with delimiter
-
-