List of utility methods to do String Encode
String | encode(String s) Escapes non-ASCII characters in URL. try { boolean escaped = false; StringBuilder out = new StringBuilder(s.length()); ByteArrayOutputStream buf = new ByteArrayOutputStream(); OutputStreamWriter w = new OutputStreamWriter(buf, "UTF-8"); for (int i = 0; i < s.length(); i++) { int c = s.charAt(i); if (c < 128 && c != ' ') { ... |
String | encode(String s, String enc) Encode a given string. if (s == null) { throw new IllegalArgumentException("String must not be null"); if (enc == null) { enc = "UTF-8"; ByteArrayInputStream bIn; try { ... |
String | encode(String s, String encoding) encode int length = s.length(); int start = 0; int i = 0; StringBuilder result = new StringBuilder(length); while (true) { while ((i < length) && isSafe(s.charAt(i))) { i++; result.append(s.substring(start, i)); if (i >= length) { return result.toString(); } else if (s.charAt(i) == ' ') { result.append('+'); i++; } else { start = i; char c; while ((i < length) && ((c = s.charAt(i)) != ' ') && !isSafe(c)) { i++; String unsafe = s.substring(start, i); byte[] bytes = unsafe.getBytes(encoding); for (int j = 0; j < bytes.length; j++) { result.append('%'); int val = bytes[j]; result.append(hex.charAt((val & 0xf0) >> 4)); result.append(hex.charAt(val & 0x0f)); start = i; |
String | encode(String source, String charsetFrom, String charsetTo) encode try { return new String(source.getBytes(charsetFrom), charsetTo); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return source; |
String | encode(String src) encode String genDelims = ":/?#[]@"; String subDelims = "!$&'()*+,;="; String unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._~"; String okChars = genDelims + subDelims + unreserved + "%"; String filesep = System.getProperty("file.separator"); if ("\\".equals(filesep)) { src = src.replaceAll("\\\\", "/"); String encoded = ""; try { byte[] bytes = src.getBytes("UTF-8"); for (int pos = 0; pos < bytes.length; pos++) { if (okChars.indexOf(bytes[pos]) >= 0) { encoded += (char) bytes[pos]; } else { encoded += String.format("%%%02X", bytes[pos]); } catch (UnsupportedEncodingException uee) { return encoded; |
byte[] | encode(String src, String charset) encode if (src == null) { return null; try { return src.getBytes(charset); } catch (UnsupportedEncodingException e) { return src.getBytes(); |
String | encode(String str) encode byte[] b = null; String s = null; try { b = str.getBytes("utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); if (b != null) { ... |
void | encode(String str, int start, int end, Writer writer) encode for (int i = start; i < end; i++) { char ch = str.charAt(i); String special = getSpecial(ch); if (special != null) { writer.write(special); } else { if ((ch & 0xff) != 0) { writer.write("&#"); ... |
InputStream | encode(String text, String charset) encode try { return new ByteArrayInputStream(text.getBytes(charset)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throwCoreException(e); return null; |
String | encode(String text, String encoding) encode return MimeUtility.encodeText(text, encoding, "Q"); |