org.jclouds.util
Class Strings2

java.lang.Object
  extended by org.jclouds.util.Strings2

public class Strings2
extends Object

Author:
Adrian Cole

Field Summary
static String UTF8_ENCODING
           
 
Constructor Summary
Strings2()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF8_ENCODING

public static final String UTF8_ENCODING
See Also:
Constant Field Values
Constructor Detail

Strings2

public Strings2()
Method Detail

urlEncode

public static String urlEncode(String in,
                               char... skipEncode)
Web browsers do not always handle '+' characters well, use the well-supported '%20' instead.


isUrlEncoded

public static boolean isUrlEncoded(String in)

urlDecode

public static String urlDecode(String in)

replaceTokens

public static String replaceTokens(String value,
                                   Iterable<Map.Entry<String,String>> tokenValues)

replaceAll

public static String replaceAll(String returnVal,
                                Pattern pattern,
                                String replace)

replaceAll

public static String replaceAll(String input,
                                char ifMatch,
                                Pattern pattern,
                                String replacement)

replaceAll

public static String replaceAll(String input,
                                char match,
                                String replacement)

toStringAndClose

public static String toStringAndClose(InputStream input)
                               throws IOException
Throws:
IOException

toInputStream

public static InputStream toInputStream(String in)

encodeString

public static byte[] encodeString(String str,
                                  String charsetName)
Encode the given string with the given encoding, if possible. If the encoding fails with UnsupportedEncodingException, log a warning and fall back to the system's default encoding.

Parameters:
str - what to encode
charsetName - the name of a supported charset
Returns:
properly encoded String.

encodeString

public static byte[] encodeString(String str)
Encode the given string with the UTF-8 encoding, the sane default. In the very unlikely event the encoding fails with UnsupportedEncodingException, log a warning and fall back to the system's default encoding.

Parameters:
str - what to encode
Returns:
properly encoded String.

replaceTokens

public static String replaceTokens(String input,
                                   Map<String,String> replacements)
replaces tokens that are expressed as {token}

ex. if input is "hello {where}"
and replacements is "where" -> "world"
then replaceTokens returns "hello world"

Parameters:
input - source to replace
replacements - token/value pairs


Copyright © 2009-2011 jclouds. All Rights Reserved.