public class StringUtils extends Object
Provides utility methods related to string operations.
Modifier and Type | Method and Description |
---|---|
static com.google.common.collect.ImmutableList<String> |
convertToHex(byte[] bytes)
Returns the given bytes in hex format.
|
static com.google.common.collect.ImmutableList<String> |
convertToHex(InputStream inputStream)
Returns the bytes of the given input stream in hex format.
|
static com.google.common.collect.ImmutableList<String> |
convertToHex(String string,
String charsetName)
Returns the bytes of the given string in hex format.
|
static byte[] |
getBytes(String string,
String charsetName)
Returns the bytes of the given string.
|
static com.google.common.collect.ImmutableList<Pair<String,String>> |
getTagAttributesAndContent(String string,
String openingTag,
String closingOfOpeningTag,
String closingTag)
For each tag, the tag attributes and the tag content are collected.
|
static String |
replace(String string,
String replacement,
int firstPosToReplace,
int lastPosToReplace)
Replaces a substring of the given string with some other string.
|
static String |
replaceTags(String string,
String openingTag,
String closingTag,
com.google.common.base.Function<String,String> replacementFunction)
For each tag, the tag is replaced with the content defined by the given replacement function.
|
static Pair<String,com.google.common.collect.ImmutableMap<String,Object>> |
replaceTags(String string,
String openingTag,
String closingOfOpeningTag,
String closingTag,
Function2<String,String,Pair<String,Map<String,Object>>> replacementFunction)
For each tag, the tag is replaced with the content defined by the given replacement function.
|
static com.google.common.collect.ImmutableList<String> |
toChunks(String string,
int chunkSize)
Splits the given string into chucks of characters of the given size.
|
static com.google.common.collect.ImmutableList<String> |
toLowerCase(List<String> input)
Converts the given strings to lower-case.
|
static String |
trimSuffix(String string,
String suffix)
Removes the given suffix from the given string.
|
public static com.google.common.collect.ImmutableList<Pair<String,String>> getTagAttributesAndContent(String string, String openingTag, String closingOfOpeningTag, String closingTag)
For each tag, the tag attributes and the tag content are collected. A tag is identified by the opening tag, the closing of the opening tag, and the closing tag.
string
- the string to investigateopeningTag
- the opening tag to matchclosingOfOpeningTag
- the closing of the opening tag to matchclosingTag
- the closing tag to matchpublic static Pair<String,com.google.common.collect.ImmutableMap<String,Object>> replaceTags(String string, String openingTag, String closingOfOpeningTag, String closingTag, Function2<String,String,Pair<String,Map<String,Object>>> replacementFunction)
For each tag, the tag is replaced with the content defined by the given replacement function. A tag is identified by the opening tag, the closing of the opening tag, and the closing tag.
string
- the string to investigateopeningTag
- the opening tag to matchclosingOfOpeningTag
- the closing of the opening tag to matchclosingTag
- the closing tag to matchreplacementFunction
- the function to convert the tag into some new stringpublic static String replaceTags(String string, String openingTag, String closingTag, com.google.common.base.Function<String,String> replacementFunction)
For each tag, the tag is replaced with the content defined by the given replacement function. A tag is identified by the opening tag and the closing tag.
string
- the string to investigateopeningTag
- the opening tag to matchclosingTag
- the closing tag to matchreplacementFunction
- the function to convert the tag into some new stringpublic static String replace(String string, String replacement, int firstPosToReplace, int lastPosToReplace)
Replaces a substring of the given string with some other string. The substring to replace is defined by the given start and end position in the current string.
string
- the string to investigatereplacement
- the replacement stringfirstPosToReplace
- the first position to replace in the stringlastPosToReplace
- the last position to replace in the stringpublic static String trimSuffix(String string, String suffix)
Removes the given suffix from the given string. If the string does not end with the suffix, the original string is returned.
string
- the string to investigatesuffix
- the suffix to removepublic static com.google.common.collect.ImmutableList<String> toLowerCase(List<String> input)
Converts the given strings to lower-case.
input
- the string to covert to lower-casepublic static com.google.common.collect.ImmutableList<String> toChunks(String string, int chunkSize)
Splits the given string into chucks of characters of the given size.
string
- the string to investigatechunkSize
- the chunk sizepublic static com.google.common.collect.ImmutableList<String> convertToHex(InputStream inputStream) throws IOException
Returns the bytes of the given input stream in hex format.
inputStream
- the input stream whose bytes to convertIOException
- thrown if an error occurs while reading from the streampublic static com.google.common.collect.ImmutableList<String> convertToHex(String string, String charsetName)
Returns the bytes of the given string in hex format.
string
- the string to convertcharsetName
- the charset to apply when converting the string to bytespublic static com.google.common.collect.ImmutableList<String> convertToHex(byte[] bytes)
Returns the given bytes in hex format.
bytes
- the bytes to convertCopyright © 2010 - 2019 edorasware ag. All Rights Reserved.