/** * Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped. * * @param bytes * array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ @Override public byte[] encode(final byte[] bytes) { return encodeUrl(WWW_FORM_URL_SAFE, bytes); }
/** * Encodes an array of bytes into an array of URL safe 7-bit * characters. Unsafe characters are escaped. * * @param bytes array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ public byte[] encode(byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); }
/** * Encode the specified value. * * @param value The value to encode. * @return The encoded value. */ public static String oauthEncode(String value) { if (value == null) { return ""; } try { return new String(URLCodec.encodeUrl(SAFE_CHARACTERS, value.getBytes("UTF-8")), "US-ASCII"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * Escape and encode a given string with allowed characters not to be * escaped and a given charset. * * @param unescaped a string * @param allowed allowed characters not to be escaped * @param charset the charset * @return the escaped string */ public static String encode(String unescaped, BitSet allowed, String charset) throws URIException { byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtil.getBytes(unescaped, charset)); return EncodingUtil.getAsciiString(rawdata); }
throw new IllegalArgumentException("Allowed bitset may not be null"); byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtil.getBytes(original, charset)); return EncodingUtil.getAsciiString(rawdata).toCharArray();
@Test public void testEncodeUrlWithNullBitSet() throws Exception { final URLCodec urlCodec = new URLCodec(); final String plain = "Hello there!"; final String encoded = new String( URLCodec.encodeUrl(null, plain.getBytes(Charsets.UTF_8))); assertEquals("Basic URL encoding test", "Hello+there%21", encoded); assertEquals("Basic URL decoding test", plain, urlCodec.decode(encoded)); this.validateState(urlCodec); }
/** * Encodes an array of bytes into an array of URL safe 7-bit * characters. Unsafe characters are escaped. * * @param bytes array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ public byte[] encode(byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); }
/** * Encodes an array of bytes into an array of URL safe 7-bit * characters. Unsafe characters are escaped. * * @param bytes array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ public byte[] encode(byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); }
/** * Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped. * * @param bytes * array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ @Override public byte[] encode(final byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); }
/** * Encodes an array of bytes into an array of URL safe 7-bit * characters. Unsafe characters are escaped. * * @param bytes array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ public byte[] encode(byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); }
/** * Encodes an array of bytes into an array of URL safe 7-bit * characters. Unsafe characters are escaped. * * @param bytes array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ public byte[] encode(byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); }
/** * Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped. * * @param bytes * array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ @Override public byte[] encode(final byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); }
/** * Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped. * * @param bytes * array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ @Override public byte[] encode(final byte[] bytes) { return encodeUrl(WWW_FORM_URL_SAFE, bytes); }
/** * Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped. * * @param bytes * array of bytes to convert to URL safe characters * @return array of bytes containing URL safe characters */ @Override public byte[] encode(final byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); }
/** * URL rewriter.<p> * * @param path path which has to be rewritten * * @return a string with the encoded path * * @throws UnsupportedEncodingException if something goes wrong while encoding the url */ protected String rewriteUrl(String path) throws UnsupportedEncodingException { return new String(URLCodec.encodeUrl(URL_SAFE_CHARS, path.getBytes("ISO-8859-1"))); }
/** * URL rewriter.<p> * * @param path path which has to be rewritten * * @return a string with the encoded path * * @throws UnsupportedEncodingException if something goes wrong while encoding the url */ protected String rewriteUrl(String path) throws UnsupportedEncodingException { return new String(URLCodec.encodeUrl(URL_SAFE_CHARS, path.getBytes("ISO-8859-1"))); }
/** * Escapes and encodes the specified string. Based on HttpClient 3.1's <tt>URIUtil.encode()</tt> method. * * @param unescaped the string to encode * @param allowed allowed characters that shouldn't be escaped * @param charset the charset to use * @return the escaped string */ private static String encode(final String unescaped, final BitSet allowed, final Charset charset) { final byte[] bytes = unescaped.getBytes(charset); final byte[] bytes2 = URLCodec.encodeUrl(allowed, bytes); return encodePercentSign(bytes2); }
/** @param user - user of modification */ public void setAuthor(String user) { // empty author is error in jrcs if (user == null || "".equals(user)) { super.setAuthor(sauthorIfEmpty); } else { byte[] enc = URLCodec.encodeUrl(safeAuthorChars, user.getBytes()); String senc = new String(enc).replace('%', '_'); super.setAuthor(senc); } } /** @return user of modification
/** * Escape and encode a string regarded as the path component of an URI with * the default protocol charset. * @param unescaped an unescaped string * @return the escaped string */ public static String encodePath(String unescaped) { byte[] rawdata = URLCodec.encodeUrl(allowed_abs_path, getBytes(unescaped, "UTF-8")); return getAsciiString(rawdata); }
public String encodeUrl(String unescaped) { byte[] rawdata = URLCodec.encodeUrl(URI.allowed_query, org.apache.commons.codec.binary.StringUtils.getBytesUtf8(unescaped)); return org.apache.commons.codec.binary.StringUtils.newStringUsAscii(rawdata); }