Merge pull request #733 from andrewgaul/remove-encode-string

Remove encodeString() and encodeString(String)
This commit is contained in:
Adrian Cole 2012-07-19 12:11:00 -07:00
commit 0fb6b12c56
1 changed files with 0 additions and 36 deletions

View File

@ -125,8 +125,6 @@ public class Strings2 {
return input; return input;
} }
public static final String UTF8_ENCODING = "UTF-8";
public static String toString(InputSupplier<? extends InputStream> supplier) public static String toString(InputSupplier<? extends InputStream> supplier)
throws IOException { throws IOException {
return CharStreams.toString(CharStreams.newReaderSupplier(supplier, return CharStreams.toString(CharStreams.newReaderSupplier(supplier,
@ -151,43 +149,9 @@ public class Strings2 {
return new ByteArrayInputStream(in.getBytes(Charsets.UTF_8)); 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 @Resource
private static Logger logger = Logger.NULL; 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> * replaces tokens that are expressed as <code>{token}</code>
* *