List of utility methods to do String Encode
String | encode(String text, String encoding) encode if (true) return text; try { byte[] bs = text.getBytes(System.getProperty("file.encoding")); ByteArrayInputStream is = new ByteArrayInputStream(bs); InputStreamReader r = new InputStreamReader(is, encoding); char[] cs = new char[bs.length]; int l = r.read(cs, 0, cs.length); ... |
String | encode(String val, String encoding) encode if (val == null) { return null; return new String(val.getBytes(encoding)); |
String | encode(String value, String encoding) Encodes a String using the set of characters allowed in a URI. int len = value.length(); StringBuilder out = new StringBuilder(len * 3 / 2); for (int charIndex = 0; charIndex < len; charIndex++) { char aChar = value.charAt(charIndex); if ((aChar <= 127) && sValidChar[aChar]) { out.append(aChar); } else if (aChar == ' ') { out.append('+'); ... |
String | encodeBase64(String str) encode Base ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream b64os = MimeUtility.encode(baos, "base64"); b64os.write(str.getBytes()); b64os.close(); return baos.toString().trim(); |
String | encodeConvenience(String str) Performs safe URI-escaping of the '%' and ' ' characters in the string for convenience sake. Matcher m = CONVENIENCE_ENCODABLE.matcher(str); boolean found = m.find(); if (found) { final char[] hexTable = HEX_TABLE; StringBuilder sb = new StringBuilder(str.length() + ENCODE_ALLOWANCE); int findStart = 0; do { final int pos = m.start(); ... |
void | encodeDataPair(final StringBuilder buffer, final String key, final String value) Encode a key/value data pair to be used in a HTTP post request. buffer.append('&').append(encode(key)).append('=').append(encode(value)); |
String | encodeDoublePercent(String input) encode Double Percent if (input.contains("%")) { input = input.replaceAll("%", "%25"); return encode(input); |
String | encodeDownloadFileName(String s) encode Download File Name try { return URLEncoder.encode(s, "UTF-8").replaceAll("\\+", "%20"); } catch (Exception e) { return ""; |
String | encodeFilename(final String filename, final String userAgent) Hack to get the correct format of the file name, based on USER-AGENT string.
String codedFilename = null; try { if (null != userAgent && -1 != userAgent.indexOf("MSIE")) { codedFilename = URLEncoder.encode(filename, DEFAULT_CHARSET); } else if (null != userAgent && -1 != userAgent.indexOf("Mozilla")) { codedFilename = MimeUtility.encodeText(filename, DEFAULT_CHARSET, "B"); } catch (UnsupportedEncodingException uee) { ... |
String | encodeFilename(String filename, String encoding) encode Filename String splChars = ".*[#$%?@].*"; if (filename.matches(splChars)) return URLEncoder.encode(filename, encoding); return filename; |