mirror of https://github.com/apache/jclouds.git
Merge pull request #733 from andrewgaul/remove-encode-string
Remove encodeString() and encodeString(String)
This commit is contained in:
commit
0fb6b12c56
|
@ -125,8 +125,6 @@ public class Strings2 {
|
|||
return input;
|
||||
}
|
||||
|
||||
public static final String UTF8_ENCODING = "UTF-8";
|
||||
|
||||
public static String toString(InputSupplier<? extends InputStream> supplier)
|
||||
throws IOException {
|
||||
return CharStreams.toString(CharStreams.newReaderSupplier(supplier,
|
||||
|
@ -151,43 +149,9 @@ public class Strings2 {
|
|||
return new ByteArrayInputStream(in.getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the given string with the given encoding, if possible. If the encoding fails with
|
||||
* {@link UnsupportedEncodingException}, log a warning and fall back to the system's default
|
||||
* encoding.
|
||||
*
|
||||
* @param str
|
||||
* what to encode
|
||||
* @param charsetName
|
||||
* the name of a supported {@link java.nio.charset.Charset </code>charset<code>}
|
||||
* @return properly encoded String.
|
||||
*/
|
||||
public static byte[] encodeString(String str, String charsetName) {
|
||||
try {
|
||||
return str.getBytes(charsetName);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.warn(e, "Failed to encode string to bytes with encoding " + charsetName
|
||||
+ ". Falling back to system's default encoding");
|
||||
return str.getBytes();
|
||||
}
|
||||
}
|
||||
|
||||
@Resource
|
||||
private static Logger logger = Logger.NULL;
|
||||
|
||||
/**
|
||||
* Encode the given string with the UTF-8 encoding, the sane default. In the very unlikely event
|
||||
* the encoding fails with {@link UnsupportedEncodingException}, log a warning and fall back to
|
||||
* the system's default encoding.
|
||||
*
|
||||
* @param str
|
||||
* what to encode
|
||||
* @return properly encoded String.
|
||||
*/
|
||||
public static byte[] encodeString(String str) {
|
||||
return encodeString(str, UTF8_ENCODING);
|
||||
}
|
||||
|
||||
/**
|
||||
* replaces tokens that are expressed as <code>{token}</code>
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue