Java Utililty Methods Encode

List of utility methods to do Encode

Description

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

Method

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) {
...
StringencodeAttribute(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;
...
voidencodeBackslashAhead(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");
...
StringencodeCodePoolData(InputStream input)
Encodes to base64 the given CodePool Data
ByteArrayOutputStream output = new ByteArrayOutputStream();
copyStream(input, output);
return Base64.getEncoder().encodeToString(output.toByteArray());
ReaderencodedInputStreamReader(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);
PropertiesencodedStringToProperties(String theEncodedPropertyString)
encoded String To Properties
try {
    return getPropertiesFromEncodedString(theEncodedPropertyString);
} catch (IOException ee) {
    return null;
StringencodeEmail(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;
StringencodeFile(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));
...
StringencodeForFilter(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.

CharacterEncoded As
*\2a
(\28
)\29
\\5c
null\00

In addition to encoding the above characters, any non-ASCII character (any character with a hex value greater then 0x7f) is also encoded and rewritten as a UTF-8 character or sequence of characters in hex notation.

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;
...
StringencodeForString(String str)
encode For String
try {
    return encode(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    return null;