List of utility methods to do Encode
byte[] | encodeAsModifiedUTF8(String str) encode As Modified UTF int strlen = str.length(); int utflen = 0; int c, count = 0; for (int i = 0; i < strlen; i++) { c = str.charAt(i); if ((c >= 0x0001) && (c <= 0x007F)) { utflen++; } else if (c > 0x07FF) { ... | ||||||||||||
String | encodeAttribute(String value) encode Attribute CharArrayWriter writer = new CharArrayWriter(); int size = value.length(); for (int i = 0; i < size; i++) { char c = value.charAt(i); switch (c) { case '&': writer.append(ENCODED_AMPERSAND); break; ... | ||||||||||||
void | encodeBackslashAhead(char c, char next, Appendable buffer) encode a char in Wiki format and append it to a buffer if (Character.isWhitespace(c)) { if (Character.isWhitespace(next) || next == Character.MAX_VALUE) return; else buffer.append('_'); } else { String hex = Integer.toHexString(c); buffer.append("\\u"); ... | ||||||||||||
String | encodeCodePoolData(InputStream input) Encodes to base64 the given CodePool Data ByteArrayOutputStream output = new ByteArrayOutputStream(); copyStream(input, output); return Base64.getEncoder().encodeToString(output.toByteArray()); | ||||||||||||
Reader | encodedInputStreamReader(InputStream stream, String encoding) Create a Reader with an explicit encoding around an InputStream. if (encoding == null) { return new InputStreamReader(stream); } else { return new InputStreamReader(stream, encoding); | ||||||||||||
Properties | encodedStringToProperties(String theEncodedPropertyString) encoded String To Properties try { return getPropertiesFromEncodedString(theEncodedPropertyString); } catch (IOException ee) { return null; | ||||||||||||
String | encodeEmail(String s) Encode non ascii characters present in emails like: =?ISO-8859-1?Q?No=20hay=20ma=F1ana?= if (s == null) { return s; Pattern p = Pattern.compile("^\\s*(.*?)\\s*(<[^>]+>)\\s*"); Matcher m = p.matcher(s); return m.matches() ? encodeTexts(m.group(1)) + " " + m.group(2) : s; | ||||||||||||
String | encodeFile(String filePath) This webService encodes the files content in Base64 format Usage: For uploading an ISVP to a remote node in the cluster, the isvp file has to be encoded and uploaded. FileInputStream fin = null; try { fin = new FileInputStream(filePath); byte[] fileContent = new byte[fin.available()]; DataInputStream din = new DataInputStream(fin); din.readFully(fileContent); BASE64Encoder encoder = new BASE64Encoder(); return new String(encoder.encode(fileContent)); ... | ||||||||||||
String | encodeForFilter(final String filterString) Encode a string so that it can be used in an LDAP search filter. The following table shows the characters that are encoded and their encoded version.
In addition to encoding the above characters, any non-ASCII character (any character with a hex value greater then if (filterString != null && filterString.length() > 0) { StringBuilder encString = new StringBuilder(filterString.length()); for (int i = 0; i < filterString.length(); i++) { char ch = filterString.charAt(i); switch (ch) { case '*': encString.append("\\2a"); break; ... | ||||||||||||
String | encodeForString(String str) encode For String try { return encode(str.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; |