Java Utililty Methods String Encode by Charset

List of utility methods to do String Encode by Charset

Description

The list of methods to do String Encode by Charset are organized into topic(s).

Method

byte[]getHeader(Charset encoding)
get Header
byte[] header = null;
if (encoding.toString().equals("UTF-32LE")) {
    header = new byte[] { (byte) 0xFF, (byte) 0xFE, (byte) 0x00, (byte) 0x00 };
} else if (encoding.toString().equals("UTF-32BE")) {
    header = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0xFE, (byte) 0xFF };
} else if (encoding.toString().equals("UTF-16LE")) {
    header = new byte[] { (byte) 0xFF, (byte) 0xFE };
} else if (encoding.toString().equals("UTF-16BE")) {
...
StringloadAsString(String locationPattern, Charset encoding)
load As String
URL url = Resources.getResource(locationPattern);
return Resources.toString(url, encoding);
StringpathEncode(String path, Charset charset)
Uri Encode a Path Fragment.
return encodeReserved(path, PATH_RESERVED_CHARACTERS, charset);
StringurlEncode(final String content, final Charset charset, final BitSet safechars, final boolean blankAsPlus)
url Encode
if (content == null) {
    return null;
final StringBuilder buf = new StringBuilder();
final ByteBuffer bb = charset.encode(content);
while (bb.hasRemaining()) {
    final int b = bb.get() & 0xff;
    if (safechars.get(b)) {
...
StringurlEncode(final String str, final Charset encoding)
url Encode
try {
    return URLEncoder.encode(str, encoding.name());
} catch (final UnsupportedEncodingException x) {
    throw new RuntimeException(x);
StringurlEncode(String url, Charset cs)
url Encode
try {
    return URLEncoder.encode(url, cs.name());
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);