本文整理汇总了Java中org.apache.commons.codec.net.URLCodec.encodeUrl方法的典型用法代码示例。如果您正苦于以下问题:Java URLCodec.encodeUrl方法的具体用法?Java URLCodec.encodeUrl怎么用?Java URLCodec.encodeUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.codec.net.URLCodec
的用法示例。
在下文中一共展示了URLCodec.encodeUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* Encodes a string into its URL safe form using the UTF-8 charset. Unsafe characters are escaped and the resulting
* string is returned in the US-ASCII charset.
* @param string The string to convert to a URL safe form
* @return URL safe string
* @throws AciURLCodecException If there was a problem during the encoding
*/
public String encode(final String string) {
// This is what we'll return...
String returnValue = null;
try {
if (string != null) {
returnValue = new String(URLCodec.encodeUrl(safeChars, string.getBytes(UTF8)), US_ASCII);
}
} catch (final UnsupportedEncodingException uee) {
// This should never ever happen as both charsets are required by the Java Spec.
throw new AciURLCodecException(uee);
}
// Return the result...
return returnValue;
}
示例2: encodePath
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* 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);
}
示例3: oauthEncode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* 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);
}
}
示例4: encodeUri
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
private static @NotNull String encodeUri(@NotNull String decodedUriNoLeadSlash) {
byte[] urlBytes = URLCodec.encodeUrl(SAFE_CHARACTERS, decodedUriNoLeadSlash.getBytes(StandardCharsets.UTF_8));
return "/" + new String(urlBytes, StandardCharsets.UTF_8);
}
示例5: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
public static String encode(String str, java.nio.charset.Charset charset) throws UnsupportedEncodingException {
return new String(URLCodec.encodeUrl(WWW_FORM_URL, str.getBytes(charset)),"us-ascii");
}
示例6: urlPath
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
public static String urlPath(String text) {
return new String(URLCodec.encodeUrl(URL_PATH, Strings.bytes(text)), Charsets.UTF_8);
}
示例7: url
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
public static String url(String text) {
return new String(URLCodec.encodeUrl(null, Strings.bytes(text)), Charsets.UTF_8);
}
示例8: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* 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 HttpException {
byte[] rawdata = URLCodec.encodeUrl(allowed,
EncodingUtils.getBytes(unescaped, charset));
return EncodingUtils.getAsciiString(rawdata);
}
示例9: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* Encodes URI string.
* <p/>
* This is a two mapping, one from original characters to octets, and
* subsequently a second from octets to URI characters:
* <p><blockquote><pre>
* original character sequence->octet sequence->URI character sequence
* </pre></blockquote><p>
* <p/>
* An escaped octet is encoded as a character triplet, consisting of the
* percent character "%" followed by the two hexadecimal digits
* representing the octet code. For example, "%20" is the escaped
* encoding for the US-ASCII space character.
* <p/>
* Conversion from the local filesystem character set to UTF-8 will
* normally involve a two step process. First convert the local character
* set to the UCS; then convert the UCS to UTF-8.
* The first step in the process can be performed by maintaining a mapping
* table that includes the local character set code and the corresponding
* UCS code.
* The next step is to convert the UCS character code to the UTF-8 encoding.
* <p/>
* Mapping between vendor codepages can be done in a very similar manner
* as described above.
* <p/>
* The only time escape encodings can allowedly be made is when a URI is
* being created from its component parts. The escape and validate methods
* are internally performed within this method.
*
* @param original the original character sequence
* @param allowed those characters that are allowed within a component
* @param charset the protocol charset
* @return URI character sequence
* @throws HttpException null component or unsupported character encoding
*/
protected static char[] encode(String original, BitSet allowed,
String charset) throws HttpException {
if (original == null) {
throw new IllegalArgumentException("Original string may not be null");
}
if (allowed == null) {
throw new IllegalArgumentException("Allowed bitset may not be null");
}
byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtils.getBytes(original, charset));
return EncodingUtils.getAsciiString(rawdata).toCharArray();
}
示例10: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* 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);
}
示例11: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* Encodes URI string.
*
* This is a two mapping, one from original characters to octets, and
* subsequently a second from octets to URI characters:
* <p><blockquote><pre>
* original character sequence->octet sequence->URI character sequence
* </pre></blockquote><p>
*
* An escaped octet is encoded as a character triplet, consisting of the
* percent character "%" followed by the two hexadecimal digits
* representing the octet code. For example, "%20" is the escaped
* encoding for the US-ASCII space character.
* <p>
* Conversion from the local filesystem character set to UTF-8 will
* normally involve a two step process. First convert the local character
* set to the UCS; then convert the UCS to UTF-8.
* The first step in the process can be performed by maintaining a mapping
* table that includes the local character set code and the corresponding
* UCS code.
* The next step is to convert the UCS character code to the UTF-8 encoding.
* <p>
* Mapping between vendor codepages can be done in a very similar manner
* as described above.
* <p>
* The only time escape encodings can allowedly be made is when a URI is
* being created from its component parts. The escape and validate methods
* are internally performed within this method.
*
* @param original the original character sequence
* @param allowed those characters that are allowed within a component
* @param charset the protocol charset
* @return URI character sequence
* @throws URIException null component or unsupported character encoding
*/
protected static char[] encode(String original, BitSet allowed,
String charset) throws URIException {
if (original == null) {
throw new IllegalArgumentException("Original string may not be null");
}
if (allowed == null) {
throw new IllegalArgumentException("Allowed bitset may not be null");
}
byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtil.getBytes(original, charset));
return EncodingUtil.getAsciiString(rawdata).toCharArray();
}
示例12: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* Encodes URI string.
*
* This is a two mapping, one from original characters to octets, and
* subsequently a second from octets to URI characters:
* <p>
* <blockquote>
*
* <pre>
* original character sequence->octet sequence->URI character sequence
* </pre>
*
* </blockquote>
* <p>
*
* An escaped octet is encoded as a character triplet, consisting of the
* percent character "%" followed by the two hexadecimal digits representing
* the octet code. For example, "%20" is the escaped encoding for the
* US-ASCII space character.
* <p>
* Conversion from the local filesystem character set to UTF-8 will normally
* involve a two step process. First convert the local character set to the
* UCS; then convert the UCS to UTF-8. The first step in the process can be
* performed by maintaining a mapping table that includes the local
* character set code and the corresponding UCS code. The next step is to
* convert the UCS character code to the UTF-8 encoding.
* <p>
* Mapping between vendor codepages can be done in a very similar manner as
* described above.
* <p>
* The only time escape encodings can allowedly be made is when a URI is
* being created from its component parts. The escape and validate methods
* are internally performed within this method.
*
* @param original
* the original character sequence
* @param allowed
* those characters that are allowed within a component
* @param charset
* the protocol charset
* @return URI character sequence
* @throws URIException
* null component or unsupported character encoding
*/
protected static char[] encode(final String original, final BitSet allowed, final String charset)
throws URIException {
if (original == null) {
throw new IllegalArgumentException("Original string may not be null");
}
if (allowed == null) {
throw new IllegalArgumentException("Allowed bitset may not be null");
}
final byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtil.getBytes(original, charset));
return EncodingUtil.getAsciiString(rawdata).toCharArray();
}
示例13: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* 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,
EncodingUtils.getBytes(unescaped, charset));
return EncodingUtils.getAsciiString(rawdata);
}
示例14: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* 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 HttpException {
byte[] rawdata = URLCodec.encodeUrl(allowed,
EncodingUtils.getBytes(unescaped, charset));
return EncodingUtils.getAsciiString(rawdata);
}
示例15: encode
import org.apache.commons.codec.net.URLCodec; //导入方法依赖的package包/类
/**
* Encodes URI string.
* <p/>
* This is a two mapping, one from original characters to octets, and
* subsequently a second from octets to URI characters:
* <p><blockquote><pre>
* original character sequence->octet sequence->URI character sequence
* </pre></blockquote><p>
* <p/>
* An escaped octet is encoded as a character triplet, consisting of the
* percent character "%" followed by the two hexadecimal digits
* representing the octet code. For example, "%20" is the escaped
* encoding for the US-ASCII space character.
* <p/>
* Conversion from the local filesystem character set to UTF-8 will
* normally involve a two step process. First convert the local character
* set to the UCS; then convert the UCS to UTF-8.
* The first step in the process can be performed by maintaining a mapping
* table that includes the local character set code and the corresponding
* UCS code.
* The next step is to convert the UCS character code to the UTF-8 encoding.
* <p/>
* Mapping between vendor codepages can be done in a very similar manner
* as described above.
* <p/>
* The only time escape encodings can allowedly be made is when a URI is
* being created from its component parts. The escape and validate methods
* are internally performed within this method.
*
* @param original the original character sequence
* @param allowed those characters that are allowed within a component
* @param charset the protocol charset
* @return URI character sequence
* @throws HttpException null component or unsupported character encoding
*/
protected static char[] encode(String original, BitSet allowed,
String charset) throws HttpException {
if (original == null) {
throw new IllegalArgumentException("Original string may not be null");
}
if (allowed == null) {
throw new IllegalArgumentException("Allowed bitset may not be null");
}
byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtils.getBytes(original, charset));
return EncodingUtils.getAsciiString(rawdata).toCharArray();
}