AMF0 Encode String
@param str
@returns {Buffer}
325124
function amf0encString(str) {
    var buf = new Buffer(3);
    buf.writeUInt8(0x02, 0);
    buf.writeUInt16BE(str.length, 1);
    return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
1040778
function (str) {

        // Max size of 1 character is 4 bytes
        var bytes = new Uint8Array(new ArrayBuffer(str.length * 4));

        var i = 0, j = 0;

        while (i < str.length) {
            var unicode_code;

            var utf16_code = str.charCodeAt(i++);
            if (utf16_code >= 0xD800 && utf16_code <= 0xDBFF) {
                // surrogate pair
                var upper = utf16_code;           // high surrogate
                var lower = str.charCodeAt(i++);  // low surrogate

                if (lower >= 0xDC00 && lower <= 0xDFFF) {
                    unicode_code =
                        (upper - 0xD800) * (1 << 10) + (1 << 16) +
                        (lower - 0xDC00);
                } else {
                    // malformed surrogate pair
                    return null;
                }
            } else {
                // not surrogate code
                unicode_code = utf16_code;
            }

            if (unicode_code < 0x80) {
                // 1-byte
                bytes[j++] = unicode_code;

            } else if (unicode_code < (1 << 11)) {
                // 2-byte
                bytes[j++] = (unicode_code >>> 6) | 0xC0;
                bytes[j++] = (unicode_code & 0x3F) | 0x80;

            } else if (unicode_code < (1 << 16)) {
                // 3-byte
                bytes[j++] = (unicode_code >>> 12) | 0xE0;
                bytes[j++] = ((unicode_code >> 6) & 0x3f) | 0x80;
                bytes[j++] = (unicode_code & 0x3F) | 0x80;

            } else if (unicode_code < (1 << 21)) {
                // 4-byte
                bytes[j++] = (unicode_code >>> 18) | 0xF0;
                bytes[j++] = ((unicode_code >> 12) & 0x3F) | 0x80;
                bytes[j++] = ((unicode_code >> 6) & 0x3F) | 0x80;
                bytes[j++] = (unicode_code & 0x3F) | 0x80;

            } else {
                // malformed UCS4 code
            }
        }

        return bytes.subarray(0, j);
    }
466477
public static String encode(String str)
    {
        String ret = str;

        try
        {
            // Obfuscate the string
            if(ret != null)
                ret = new String(Base64.encodeBase64(ret.getBytes()));
        }
        catch(NoClassDefFoundError e)
        {
            System.out.println("WARNING: unable to encode: "
                +e.getClass().getName()+": "+e.getMessage());
        }

        return ret;
    }
1167635
function encodeMimeHeader( $str )
    {
        if ( !$this->TextCodec )
        {
             $this->TextCodec = eZTextCodec::instance( $this->contentCharset(), $this->outputCharset() );
        }

        if ( function_exists( "mb_encode_mimeheader" ) )
        {
            $encoded = mb_encode_mimeheader( $str, $this->TextCodec->InputCharsetCode, "B", eZMail::lineSeparator() );
        }
        else
        {
            if (  0 == preg_match_all( '/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches ) )
                return $str;

            $maxlen = 75 - 7 - strlen( $this->TextCodec->InputCharsetCode );

            $encoding = 'B';
            $encoded = base64_encode( $str );
            $maxlen -= $maxlen % 4;
            $encoded = trim( chunk_split( $encoded, $maxlen, "\n" ) );

            $encoded = preg_replace( '/^(.*)$/m', " =?".$this->TextCodec->InputCharsetCode."?$encoding?\\1?=", $encoded );

            $encoded = trim( str_replace( "\n", eZMail::lineSeparator(), $encoded ) );
        }

        return $encoded;
    }
1249251
function amf0decLongString(buf) {
    var sLen = buf.readUInt32BE(1);
    return { len: 5 + sLen, value: buf.toString('utf8', 5, 5 + sLen) }
}
326569
public static String md5(String str) {
		String md5 = encode(str, "MD5").toLowerCase();
		return md5;
	}
17252
public static final String base64Decode(String str) {
        if (str == null) {
            return null;
        } else {
            byte data[] = getBytes(str);
            return toString(base64Decode(data));
        }
    }
531169
private String encode(String str) {
        if (str == null) {
            return null;
        }
        try {
            return URLEncoder.encode(str, Charsets.UTF_8.name());
        } catch (UnsupportedEncodingException e) {
            // Should never happen
            throw Throwables.propagate(e);
        }
    }
709806
function amf0Encode(a) {
    var buf = new Buffer(0);
    a.forEach(function (o) {
        buf = Buffer.concat([buf, amf0EncodeOne(o)]);
    });
    return buf;
}
145804
function (str) {
                str = stringify(str);
                var byteArray = [];

                for (var i = 0, l = str.length, ch; i < l; i++) {
                    ch = str.charCodeAt(i);
                    byteArray.push(ch >> 8);
                    byteArray.push(ch & 0xFF);
                }

                return byteArray;
            }
74168
function encode(arr, buf) {
  assert(Array.isArray(arr), 'array expected');
  buf = buf || new Buffer(0);
  buf = _arr(buf, arr);
  return buf;
}
88868
function b64DecodeUnicode(str) {
  // Going backwards: from bytestream, to percent-encoding, to original string.
  return decodeURIComponent(atob(str).split('').map(function (c) {
    return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
  }).join(''));
}
523456
function b64EncodeUnicode(str) {
  return btoa(
    encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
      function toSolidBytes(match, p1) {
        return String.fromCharCode('0x' + p1);
      }));
}
338615
function createBuffer(str, encoding) {
  if (BUFFER_FROM) {
    return Buffer.from(str, encoding || ENCODING);
  }
  return new Buffer(str, encoding || ENCODING);
}
1154766
function _bufferToString(buffer) {
        var str = '';
        var uint16Array = new Uint16Array(buffer);

        try {
            str = String.fromCharCode.apply(null, uint16Array);
        } catch (e) {
            // This is a fallback implementation in case the first one does
            // not work. This is required to get the phantomjs passing...
            for (var i = 0; i < uint16Array.length; i++) {
                str += String.fromCharCode(uint16Array[i]);
            }
        }

        return str;
    }
413606
private String encodeHttpParameter(String str){
		
		//It translates the empty space
		String encoded = str.replaceAll(" ", "%20");
		//It translates the & symbol				
		encoded = encoded.replaceAll("&", "%26");
		
//		encoded = encoded.replaceAll("$", "%24");
//		encoded = encoded.replaceAll("`", "%60");
//		encoded = encoded.replaceAll(":", "%3A");
//		encoded = encoded.replaceAll("<", "%3C");
//		encoded = encoded.replaceAll(">", "%3E");
//		encoded = encoded.replaceAll("[", "%5B");
//		encoded = encoded.replaceAll("]", "%5D");
//		encoded = encoded.replaceAll("{", "%7B");
//		encoded = encoded.replaceAll("}", "%7D");
		
		return encoded;
	}
309767
function fromString(str) {
  const bytes = [];

  for (let n = 0, l = str.length; n < l; n++) {
    const hex = Number(str.charCodeAt(n)).toString(16);
    bytes.push(hex);
  }

  return '0x' + bytes.join('');
}