Encodes a string.<p>

@param s the input string
@return the encoded string
341424
public static String encodeString(String s) {

        try {
            return CODEC.encode(s.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // shouldn't happen
            return null;
        }
    }
1087569
public static byte[] decode(String s) {
        if (s == null) {
            throw new NullPointerException("Input string was null.");
        }

        byte[] bytes = s.getBytes(UTF_8);
        return decode(bytes, 0, bytes.length);
    }
104276
public static String encodeHex(String s) {
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      if (isAlphanumeric(c)) result.append(c);
      else result.append(Integer.toHexString(s.charAt(i)).toUpperCase());
    }
    return (result.toString());
  }
1307538
public String urlDecode(String s) {
        if (s == null || s.isEmpty()) {
            return s;
        }
        return URL.decodeQueryString(s);
    }
1145248
public void writeMediumString( String s ) {
        final byte[] bytes = DynamicByteBufferHelper.bytes( s );
        this.addUnsignedShort( bytes.length );
        this.add( bytes );
    }
1372262
public static byte[] decode(String s) {
		byte[] bytes;
		try {
			bytes = s.getBytes(PREFERRED_ENCODING);
		} // end try
		catch (java.io.UnsupportedEncodingException uee) {
			bytes = s.getBytes();
		} // end catch

		// Decode
		bytes = decode(bytes);

		return bytes;
	}
1003451
public static byte[] compress(String s, Charset encoding)
            throws IOException
    {
        byte[] data = s.getBytes(encoding);
        return compress(data);
    }
219530
public static String decodeString(String s) {
    	int pos_amp = s.indexOf('&');
    	if (pos_amp == -1) return s;
    	
    	int pos_sc;
    	int pos_a;
    	StringBuffer buf = new StringBuffer(s.substring(0, pos_amp));
    	char replace;
    	while (true) {
    		pos_sc = s.indexOf(';', pos_amp);
    		if (pos_sc == -1) {
    			buf.append(s.substring(pos_amp));
    			return buf.toString();
    		}
    		pos_a = s.indexOf('&', pos_amp + 1);
    		while (pos_a != -1 && pos_a < pos_sc) {
    			buf.append(s.substring(pos_amp, pos_a));
    			pos_amp = pos_a;
    			pos_a = s.indexOf('&', pos_amp + 1);
    		}
    		replace = decodeEntity(s.substring(pos_amp + 1, pos_sc));
    		if (s.length() < pos_sc + 1) {
    			return buf.toString();
    		}
    		if (replace == '\0') {
    			buf.append(s.substring(pos_amp, pos_sc + 1));
    		}
    		else {
    			buf.append(replace);
    		}
    		pos_amp = s.indexOf('&', pos_sc);
    		if (pos_amp == -1) {
    			buf.append(s.substring(pos_sc + 1));
    			return buf.toString();
    		}
    		else {
    			buf.append(s.substring(pos_sc + 1, pos_amp));
    		}
    	}
    }
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);
        }
    }
583204
public static byte[] decode(String s)
    {
        int len = s.length();
        if (len % 2 != 0)
        {
            return null;
        }

        byte[] bytes = new byte[len / 2];
        int pos = 0;

        for (int i = 0; i < len; i += 2)
        {
            byte hi = (byte) Character.digit(s.charAt(i), 16);
            byte lo = (byte) Character.digit(s.charAt(i + 1), 16);
            bytes[pos++] = (byte) (hi * 16 + lo);
        }

        return bytes;
    }
860261
static CharSequence decode(final CharSequence s) {
    if (!contains(s, '%')) {
      return s.toString();
    }
    return decode0(s);
  }
931535
public static String encode(String str) {
    if (str == null) {
      return "";
    }

    return ESCAPER.escape(str)
      .replaceAll("\\!", "%21")
      .replaceAll("\\$", "%24")
      .replaceAll("\\&", "%26")
      .replaceAll("\\'", "%27")
      .replaceAll("\\(", "%28")
      .replaceAll("\\)", "%29")
      .replaceAll("\\*", "%2A")
      .replaceAll("\\+", "%2B")
      .replaceAll("\\,", "%2C")
      .replaceAll("\\/", "%2F")
      .replaceAll("\\:", "%3A")
      .replaceAll("\\;", "%3B")
      .replaceAll("\\=", "%3D")
      .replaceAll("\\@", "%40")
      .replaceAll("\\[", "%5B")
      .replaceAll("\\]", "%5D");
  }
564793
public static String escapeJavaString(String s)
  {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < s.length(); i++) {
      char ch = s.charAt(i);

      switch (ch) {
      case '\\':
        sb.append("\\\\");
        break;
      case '\n':
        sb.append("\\n");
        break;
      case '\r':
        sb.append("\\r");
        break;
      case '"':
        sb.append("\\\"");
        break;
      default:
        sb.append(ch);
      }
    }

    return sb.toString();
  }
153468
static String urlencode(final String s) {
		try {
			return URLEncoder.encode(s, CHARSET_NAME);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
614826
public static String urlFormEncode(final String s)
        {
        if (StringUtils.isBlank(s))
            {
            LOG.warn("Could not encode blank string");
            throw new IllegalArgumentException("Blank string");
            }
        try
            {
            return URLEncoder.encode(s, "UTF-8");
            }
        catch (final UnsupportedEncodingException e)
            {
            LOG.error ("Could not encode: " + s, e);            
            return s;
            }
        }
186496
private static String base64EncodeToString(String s) {
    final byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
    return Base64.encodeBase64String(bytes);
  }
1298515
private static final String urlEncode(String s) {
        try {
            return URLEncoder.encode(s, "UTF-8");
        } catch (Exception e) {
            logger.warn("Failed to encode '" + s + "'", e);
            return s;
        }
    }