public class Strings2 extends Object
Modifier and Type | Field and Description |
---|---|
static String |
UTF8_ENCODING |
Constructor and Description |
---|
Strings2() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
encodeString(String str)
Encode the given string with the UTF-8 encoding, the sane default.
|
static byte[] |
encodeString(String str,
String charsetName)
Encode the given string with the given encoding, if possible.
|
static boolean |
isUrlEncoded(String in) |
static String |
replaceAll(String input,
char ifMatch,
Pattern pattern,
String replacement) |
static String |
replaceAll(String input,
char match,
String replacement) |
static String |
replaceAll(String returnVal,
Pattern pattern,
String replace) |
static String |
replaceTokens(String value,
Iterable<Map.Entry<String,String>> tokenValues) |
static String |
replaceTokens(String input,
Map<String,String> replacements)
replaces tokens that are expressed as
{token}
ex. |
static InputStream |
toInputStream(String in) |
static String |
toStringAndClose(InputStream input) |
static String |
urlDecode(String in) |
static String |
urlEncode(String in,
char... skipEncode)
Web browsers do not always handle '+' characters well, use the well-supported '%20' instead.
|
public static final String UTF8_ENCODING
public static String urlEncode(String in, char... skipEncode)
public static boolean isUrlEncoded(String in)
public static String replaceTokens(String value, Iterable<Map.Entry<String,String>> tokenValues)
public static String replaceAll(String input, char ifMatch, Pattern pattern, String replacement)
public static String toStringAndClose(InputStream input) throws IOException
IOException
public static InputStream toInputStream(String in)
public static byte[] encodeString(String str, String charsetName)
UnsupportedEncodingException
, log a warning and fall back to the system's default
encoding.str
- what to encodecharsetName
- the name of a supported
charset
public static byte[] encodeString(String str)
UnsupportedEncodingException
, log a warning and fall back to
the system's default encoding.str
- what to encodepublic static String replaceTokens(String input, Map<String,String> replacements)
{token}
ex. if input is "hello {where}"input
- source to replacereplacements
- token/value pairsCopyright © 2009-2012 jclouds. All Rights Reserved.