org.apache.commons.httpclient.URI.encode()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(93)

本文整理了Java中org.apache.commons.httpclient.URI.encode()方法的一些代码示例,展示了URI.encode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URI.encode()方法的具体详情如下:
包路径:org.apache.commons.httpclient.URI
类名称:URI
方法名:encode

URI.encode介绍

[英]Encodes URI string. This is a two mapping, one from original characters to octets, and subsequently a second from octets to URI characters:

original character sequence->octet sequence->URI character sequence

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.

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.

Mapping between vendor codepages can be done in a very similar manner as described above.

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.
[中]对URI字符串进行编码。这是一个两个映射,一个从原始字符到八位字节,然后第二个从八位字节到URI字符:

original character sequence->octet sequence->URI character sequence

转义八位字节编码为字符三元组,由百分比字符“%”和代表八位字节代码的两个十六进制数字组成。例如,“%20”是US-ASCII空格字符的转义编码。
从本地文件系统字符集到UTF-8的转换通常需要两个步骤。首先将本地字符集转换为UCS;然后将UCS转换为UTF-8。该过程的第一步可以通过维护包含本地字符集代码和相应UCS代码的映射表来执行。下一步是将UCS字符代码转换为UTF-8编码。
供应商代码页之间的映射可以以与上述非常类似的方式完成。
唯一允许进行转义编码的时间是从其组件创建URI时。escape和validate方法在该方法内部执行。

代码示例

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Escape and encode a given string with allowed characters not to be
 * escaped.
 *
 * @param unescapedComponent an unescaped component
 * @param allowed allowed characters not to be escaped
 * @param charset the charset to encode
 * @return the escaped and encoded string
 * 
 * @throws URIException if the charset is not supported
 * 
 * @deprecated use org.apache.commons.codec.net.URLCodec
 */
public static char[] encode(String unescapedComponent, BitSet allowed, String charset) 
  throws URIException {
  return URI.encode(unescapedComponent, allowed, charset);
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Set the fragment.
 *
 * @param fragment the fragment string.
 * @throws URIException If an error occurs.
 */
public void setFragment(String fragment) throws URIException {
  if (fragment == null || fragment.length() == 0) {
    _fragment = (fragment == null) ? null : fragment.toCharArray();
    hash = 0;
    return;
  }
  _fragment = encode(fragment, allowed_fragment, getProtocolCharset());
  hash = 0;
}

代码示例来源:origin: commons-httpclient/commons-httpclient

_path = encode(path, allowed_abs_path, charset);
} else if (_is_rel_path) {
  StringBuffer buff = new StringBuffer(path.length());
    buff.append(encode(path.substring(0, at), allowed_rel_path,
          charset));
    buff.append(encode(path.substring(at), allowed_abs_path,
          charset));
  } else {
    buff.append(encode(path, allowed_rel_path, charset));
  buf.insert(0, encode(path.substring(0, 1), uric_no_slash, charset));
  buf.insert(1, encode(path.substring(1), uric, charset));
  _opaque = buf.toString().toCharArray();
} else {

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Set the query.
 * <p>
 * When a query string is not misunderstood the reserved special characters
 * ("&amp;", "=", "+", ",", and "$") within a query component, it is
 * recommended to use in encoding the whole query with this method.
 * <p>
 * The additional APIs for the special purpose using by the reserved
 * special characters used in each protocol are implemented in each protocol
 * classes inherited from <code>URI</code>.  So refer to the same-named APIs
 * implemented in each specific protocol instance.
 *
 * @param query the query string.
 * @throws URIException incomplete trailing escape pattern or unsupported
 * character encoding
 * @see #encode
 */
public void setQuery(String query) throws URIException {
  if (query == null || query.length() == 0) {
    _query = (query == null) ? null : query.toCharArray();
    setURI();
    return;
  }
  setRawQuery(encode(query, allowed_query, getProtocolCharset()));
}

代码示例来源:origin: commons-httpclient/commons-httpclient

: encode(original.substring(0, next), allowed_userinfo,
      charset);
from = next + 1;
  : encode(original.substring(from, next), allowed_IPv6reference,
      charset);
  _authority = encode(original, allowed_reg_name, charset);

代码示例来源:origin: commons-httpclient/commons-httpclient

throw new URIException(URIException.PARSING, "incorrect scheme");
_opaque = encode(schemeSpecificPart, allowed_opaque_part,
    getProtocolCharset());

代码示例来源:origin: commons-httpclient/commons-httpclient

_query = encode(tmp.substring(at + 1, next), allowed_query, charset);
} else {
  _fragment = (escaped) ? tmp.substring(at + 1).toCharArray() 
    : encode(tmp.substring(at + 1), allowed_fragment, charset);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient

/**
 * Escape and encode a given string with allowed characters not to be
 * escaped.
 *
 * @param unescapedComponent an unescaped component
 * @param allowed allowed characters not to be escaped
 * @param charset the charset to encode
 * @return the escaped and encoded string
 * 
 * @throws URIException if the charset is not supported
 * 
 * @deprecated use org.apache.commons.codec.net.URLCodec
 */
public static char[] encode(String unescapedComponent, BitSet allowed, String charset) 
  throws URIException {
  return URI.encode(unescapedComponent, allowed, charset);
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Escape and encode a given string with allowed characters not to be
 * escaped.
 *
 * @param unescapedComponent an unescaped component
 * @param allowed allowed characters not to be escaped
 * @param charset the charset to encode
 * @return the escaped and encoded string
 * 
 * @throws URIException if the charset is not supported
 * 
 * @deprecated use org.apache.commons.codec.net.URLCodec
 */
public static char[] encode(String unescapedComponent, BitSet allowed, String charset) 
  throws URIException {
  return URI.encode(unescapedComponent, allowed, charset);
}

代码示例来源:origin: org.apache.commons/httpclient

/**
 * Escape and encode a given string with allowed characters not to be
 * escaped.
 *
 * @param unescapedComponent an unescaped component
 * @param allowed allowed characters not to be escaped
 * @param charset the charset to encode
 * @return the escaped and encoded string
 * 
 * @throws URIException if the charset is not supported
 * 
 * @deprecated use org.apache.commons.codec.net.URLCodec
 */
public static char[] encode(String unescapedComponent, BitSet allowed, String charset) 
  throws URIException {
  return URI.encode(unescapedComponent, allowed, charset);
}

代码示例来源:origin: org.wso2.commons-httpclient/commons-httpclient

/**
 * Escape and encode a given string with allowed characters not to be
 * escaped.
 *
 * @param unescapedComponent an unescaped component
 * @param allowed allowed characters not to be escaped
 * @param charset the charset to encode
 * @return the escaped and encoded string
 * 
 * @throws URIException if the charset is not supported
 * 
 * @deprecated use org.apache.commons.codec.net.URLCodec
 */
public static char[] encode(String unescapedComponent, BitSet allowed, String charset) 
  throws URIException {
  return URI.encode(unescapedComponent, allowed, charset);
}

代码示例来源:origin: org.zaproxy/zap

/**
 * Set the fragment.
 *
 * @param fragment the fragment string.
 * @throws URIException If an error occurs.
 */
public void setFragment(String fragment) throws URIException {
  if (fragment == null || fragment.length() == 0) {
    _fragment = (fragment == null) ? null : fragment.toCharArray();
    hash = 0;
    return;
  }
  _fragment = encode(fragment, allowed_fragment, getProtocolCharset());
  hash = 0;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient

/**
 * Set the fragment.
 *
 * @param fragment the fragment string.
 * @throws URIException If an error occurs.
 */
public void setFragment(String fragment) throws URIException {
  if (fragment == null || fragment.length() == 0) {
    _fragment = (fragment == null) ? null : fragment.toCharArray();
    hash = 0;
    return;
  }
  _fragment = encode(fragment, allowed_fragment, getProtocolCharset());
  hash = 0;
}

代码示例来源:origin: org.wso2.commons-httpclient/commons-httpclient

/**
 * Set the fragment.
 *
 * @param fragment the fragment string.
 * @throws URIException If an error occurs.
 */
public void setFragment(String fragment) throws URIException {
  if (fragment == null || fragment.length() == 0) {
    _fragment = (fragment == null) ? null : fragment.toCharArray();
    hash = 0;
    return;
  }
  _fragment = encode(fragment, allowed_fragment, getProtocolCharset());
  hash = 0;
}

代码示例来源:origin: org.apache.commons/httpclient

/**
 * Set the fragment.
 *
 * @param fragment the fragment string.
 * @throws URIException If an error occurs.
 */
public void setFragment(String fragment) throws URIException {
  if (fragment == null || fragment.length() == 0) {
    _fragment = (fragment == null) ? null : fragment.toCharArray();
    hash = 0;
    return;
  }
  _fragment = encode(fragment, allowed_fragment, getProtocolCharset());
  hash = 0;
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Set the fragment.
 *
 * @param fragment the fragment string.
 * @throws URIException If an error occurs.
 */
public void setFragment(String fragment) throws URIException {
  if (fragment == null || fragment.length() == 0) {
    _fragment = (fragment == null) ? null : fragment.toCharArray();
    hash = 0;
    return;
  }
  _fragment = encode(fragment, allowed_fragment, getProtocolCharset());
  hash = 0;
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Set the query.
 * <p>
 * When a query string is not misunderstood the reserved special characters
 * ("&amp;", "=", "+", ",", and "$") within a query component, it is
 * recommended to use in encoding the whole query with this method.
 * <p>
 * The additional APIs for the special purpose using by the reserved
 * special characters used in each protocol are implemented in each protocol
 * classes inherited from <code>URI</code>.  So refer to the same-named APIs
 * implemented in each specific protocol instance.
 *
 * @param query the query string.
 * @throws URIException incomplete trailing escape pattern or unsupported
 * character encoding
 * @see #encode
 */
public void setQuery(String query) throws URIException {
  if (query == null || query.length() == 0) {
    _query = (query == null) ? null : query.toCharArray();
    setURI();
    return;
  }
  setRawQuery(encode(query, allowed_query, getProtocolCharset()));
}

代码示例来源:origin: org.zaproxy/zap

/**
 * Set the query.
 * <p>
 * When a query string is not misunderstood the reserved special characters
 * ("&amp;", "=", "+", ",", and "$") within a query component, it is
 * recommended to use in encoding the whole query with this method.
 * <p>
 * The additional APIs for the special purpose using by the reserved
 * special characters used in each protocol are implemented in each protocol
 * classes inherited from <code>URI</code>.  So refer to the same-named APIs
 * implemented in each specific protocol instance.
 *
 * @param query the query string.
 * @throws URIException incomplete trailing escape pattern or unsupported
 * character encoding
 * @see #encode
 */
public void setQuery(String query) throws URIException {
  if (query == null || query.length() == 0) {
    _query = (query == null) ? null : query.toCharArray();
    setURI();
    return;
  }
  setRawQuery(encode(query, allowed_query, getProtocolCharset()));
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient

/**
 * Set the query.
 * <p>
 * When a query string is not misunderstood the reserved special characters
 * ("&amp;", "=", "+", ",", and "$") within a query component, it is
 * recommended to use in encoding the whole query with this method.
 * <p>
 * The additional APIs for the special purpose using by the reserved
 * special characters used in each protocol are implemented in each protocol
 * classes inherited from <code>URI</code>.  So refer to the same-named APIs
 * implemented in each specific protocol instance.
 *
 * @param query the query string.
 * @throws URIException incomplete trailing escape pattern or unsupported
 * character encoding
 * @see #encode
 */
public void setQuery(String query) throws URIException {
  if (query == null || query.length() == 0) {
    _query = (query == null) ? null : query.toCharArray();
    setURI();
    return;
  }
  setRawQuery(encode(query, allowed_query, getProtocolCharset()));
}

代码示例来源:origin: org.apache.commons/httpclient

/**
 * Set the query.
 * <p>
 * When a query string is not misunderstood the reserved special characters
 * ("&amp;", "=", "+", ",", and "$") within a query component, it is
 * recommended to use in encoding the whole query with this method.
 * <p>
 * The additional APIs for the special purpose using by the reserved
 * special characters used in each protocol are implemented in each protocol
 * classes inherited from <code>URI</code>.  So refer to the same-named APIs
 * implemented in each specific protocol instance.
 *
 * @param query the query string.
 * @throws URIException incomplete trailing escape pattern or unsupported
 * character encoding
 * @see #encode
 */
public void setQuery(String query) throws URIException {
  if (query == null || query.length() == 0) {
    _query = (query == null) ? null : query.toCharArray();
    setURI();
    return;
  }
  setRawQuery(encode(query, allowed_query, getProtocolCharset()));
}

相关文章