本文整理了Java中org.restlet.data.Reference.encode
方法的一些代码示例,展示了Reference.encode
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference.encode
方法的具体详情如下:
包路径:org.restlet.data.Reference
类名称:Reference
方法名:encode
[英]Encodes a given string using the standard URI encoding mechanism and the UTF-8 character set.
[中]使用标准URI编码机制和UTF-8字符集对给定字符串进行编码。
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Encodes a given string using the standard URI encoding mechanism and the
* UTF-8 character set.
*
* @param toEncode
* The string to encode.
* @return The encoded string.
*/
public static String encode(String toEncode) {
return encode(toEncode, true, CharacterSet.UTF_8);
}
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
/**
* Encodes a given string using the standard URI encoding mechanism and the
* UTF-8 character set.
*
* @param toEncode
* The string to encode.
* @return The encoded string.
*/
public static String encode(String toEncode) {
return encode(toEncode, true, CharacterSet.UTF_8);
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Encodes a given string using the standard URI encoding mechanism and the
* UTF-8 character set. Useful to prevent the usage of '+' to encode spaces
* (%20 instead). The '*' characters are encoded as %2A and %7E are replaced
* by '~'.
*
* @param toEncode
* The string to encode.
* @param queryString
* True if the string to encode is part of a query string instead
* of a HTML form post.
* @return The encoded string.
*/
public static String encode(String toEncode, boolean queryString) {
return encode(toEncode, queryString, CharacterSet.UTF_8);
}
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
/**
* Encodes a given string using the standard URI encoding mechanism and the
* UTF-8 character set. Useful to prevent the usage of '+' to encode spaces
* (%20 instead). The '*' characters are encoded as %2A and %7E are replaced
* by '~'.
*
* @param toEncode
* The string to encode.
* @param queryString
* True if the string to encode is part of a query string instead
* of a HTML form post.
* @return The encoded string.
*/
public static String encode(String toEncode, boolean queryString) {
return encode(toEncode, queryString, CharacterSet.UTF_8);
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Encodes a given string using the standard URI encoding mechanism. If the
* provided character set is null, the string is returned but not encoded.
*
* <em><strong>Note:</strong> The <a
* href="http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars">
* World Wide Web Consortium Recommendation</a> states that UTF-8 should be
* used. Not doing so may introduce incompatibilities.</em>
*
* @param toEncode
* The string to encode.
* @param characterSet
* The supported character encoding.
* @return The encoded string or null if the named character encoding is not
* supported.
*/
public static String encode(String toEncode, CharacterSet characterSet) {
return encode(toEncode, true, characterSet);
}
代码示例来源:origin: org.restlet/org.restlet
/**
* According to the type of the variable, encodes the value given in
* parameters.
*
* @param value
* The value to encode.
* @return The encoded value, according to the variable type.
*/
public String encode(String value) {
switch (this.type) {
case Variable.TYPE_URI_ALL:
return Reference.encode(value);
case Variable.TYPE_URI_UNRESERVED:
return Reference.encode(value);
case Variable.TYPE_URI_FRAGMENT:
return Reference.encode(value);
case Variable.TYPE_URI_PATH:
return Reference.encode(value);
case Variable.TYPE_URI_QUERY:
return Reference.encode(value);
case Variable.TYPE_URI_SEGMENT:
return Reference.encode(value);
default:
return value;
}
}
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
/**
* Encodes a given string using the standard URI encoding mechanism. If the
* provided character set is null, the string is returned but not encoded.
*
* <em><strong>Note:</strong> The <a
* href="http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars">
* World Wide Web Consortium Recommendation</a> states that UTF-8 should be
* used. Not doing so may introduce incompatibilities.</em>
*
* @param toEncode
* The string to encode.
* @param characterSet
* The supported character encoding.
* @return The encoded string or null if the named character encoding is not
* supported.
*/
public static String encode(String toEncode, CharacterSet characterSet) {
return encode(toEncode, true, characterSet);
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* According to the type of the variable, encodes the value given in
* parameters.
*
* @param value
* The value to encode.
* @return The encoded value, according to the variable type.
*/
public String encode(String value) {
switch (this.type) {
case Variable.TYPE_URI_ALL:
return Reference.encode(value);
case Variable.TYPE_URI_UNRESERVED:
return Reference.encode(value);
case Variable.TYPE_URI_FRAGMENT:
return Reference.encode(value);
case Variable.TYPE_URI_PATH:
return Reference.encode(value);
case Variable.TYPE_URI_QUERY:
return Reference.encode(value);
case Variable.TYPE_URI_SEGMENT:
return Reference.encode(value);
default:
return value;
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Formats and appends a source string as an URI encoded string.
*
* @param source
* The source string to format.
* @param characterSet
* The supported character encoding.
* @return This writer.
*/
public HeaderWriter<V> appendUriEncoded(CharSequence source,
CharacterSet characterSet) {
return append(Reference.encode(source.toString(), characterSet));
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Adds a parameter to the query component. The name and value are
* automatically URL encoded if necessary.
*
* @param name
* The parameter name.
* @param value
* The optional parameter value.
* @return The updated reference.
*/
public Reference addQueryParameter(String name, String value) {
String query = getQuery();
if (query == null) {
if (value == null) {
setQuery(encode(name));
} else {
setQuery(encode(name) + '=' + encode(value));
}
} else {
if (value == null) {
setQuery(query + '&' + encode(name));
} else {
setQuery(query + '&' + encode(name) + '=' + encode(value));
}
}
return this;
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Adds a parameter to the query component. The name and value are
* automatically encoded if necessary.
*
* @param name
* The parameter name.
* @param value
* The optional parameter value.
* @return The updated reference.
*/
public Reference addQueryParameter(String name, String value) {
final String query = getQuery();
if (query == null) {
if (value == null) {
setQuery(encode(name));
} else {
setQuery(encode(name) + '=' + encode(value));
}
} else {
if (value == null) {
setQuery(query + '&' + encode(name));
} else {
setQuery(query + '&' + encode(name) + '=' + encode(value));
}
}
return this;
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Normalize a path by converting all the system-dependant separator
* characters to the standard '/' separator character.
*
* @param path
* The path to normalize.
* @return The normalize path.
*/
public static String normalizePath(String path) {
final StringBuilder result = new StringBuilder();
char nextChar;
for (int i = 0; i < path.length(); i++) {
nextChar = path.charAt(i);
if ((nextChar == '\\')) {
// Convert the Windows style path separator to the standard path
// separator
result.append('/');
} else if (!isValid(nextChar)) {
result.append(Reference.encode("" + nextChar));
} else {
result.append(nextChar);
}
}
return result.toString();
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Normalize a path by converting all the system-dependent separator
* characters to the standard '/' separator character.
*
* @param path
* The path to normalize.
* @return The normalize path.
*/
public static String normalizePath(String path) {
final StringBuilder result = new StringBuilder();
char nextChar;
for (int i = 0; i < path.length(); i++) {
nextChar = path.charAt(i);
if ((nextChar == File.separatorChar)) {
// Convert the Windows style path separator
// to the standard path separator
result.append('/');
} else if (!isUnreserved(nextChar)) {
result.append(Reference.encode("" + nextChar));
} else {
result.append(nextChar);
}
}
return result.toString();
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Encodes the parameter into the target buffer.
*
* @param buffer
* The target buffer.
* @param characterSet
* The character set to use.
* @throws IOException
*/
public void encode(Appendable buffer, CharacterSet characterSet)
throws IOException {
if (getName() != null) {
buffer.append(Reference.encode(getName(), characterSet));
if (getValue() != null) {
buffer.append('=');
buffer.append(Reference.encode(getValue(), characterSet));
}
}
}
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
/**
* Encodes the parameter into the target buffer.
*
* @param buffer
* The target buffer.
* @param characterSet
* The character set to use.
* @throws IOException
*/
public void encode(Appendable buffer, CharacterSet characterSet)
throws IOException {
if (getName() != null) {
buffer.append(Reference.encode(getName(), characterSet));
if (getValue() != null) {
buffer.append('=');
buffer.append(Reference.encode(getValue(), characterSet));
}
}
}
代码示例来源:origin: org.restlet.jse/org.restlet.ext.html
/**
* Encodes the parameter into the target buffer.
*
* @param buffer
* The target buffer.
* @param queryString
* True if the target is a query string.
* @throws IOException
*/
public void encode(Appendable buffer, boolean queryString)
throws IOException {
if (getName() != null) {
buffer.append(Reference.encode(getName(), queryString));
if (getValue() != null) {
buffer.append('=');
buffer.append(Reference.encode(getValue(), queryString));
}
}
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Encodes the parameter and appends the result to the given buffer. Uses
* the standard URI encoding mechanism.
*
* @param buffer
* The buffer to append.
* @param characterSet
* The supported character encoding
* @throws IOException
*/
public void encode(Appendable buffer, CharacterSet characterSet)
throws IOException {
if (getName() != null) {
buffer.append(Reference.encode(getName(), characterSet));
if (getValue() != null) {
buffer.append('=');
buffer.append(Reference.encode(getValue(), characterSet));
}
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Adds a segment at the end of the path. If the current path doesn't end
* with a slash character, one is inserted before the new segment value. The
* value is automatically encoded if necessary.
*
* @param value
* The segment value to add.
* @return The updated reference.
*/
public Reference addSegment(String value) {
final String path = getPath();
if (value != null) {
if (path == null) {
setPath("/" + value);
} else if (path.endsWith("/")) {
setPath(path + encode(value));
} else {
setPath(path + "/" + encode(value));
}
}
return this;
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Adds a segment at the end of the path. If the current path doesn't end
* with a slash character, one is inserted before the new segment value. The
* value is automatically encoded if necessary.
*
* @param value
* The segment value to add.
* @return The updated reference.
*/
public Reference addSegment(String value) {
final String path = getPath();
if (value != null) {
if (path == null) {
setPath("/" + value);
} else {
if (path.endsWith("/")) {
setPath(path + encode(value));
} else {
setPath(path + "/" + encode(value));
}
}
}
return this;
}
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
/**
* Adds a segment at the end of the path. If the current path doesn't end
* with a slash character, one is inserted before the new segment value. The
* value is automatically encoded if necessary.
*
* @param value
* The segment value to add.
* @return The updated reference.
*/
public Reference addSegment(String value) {
final String path = getPath();
if (value != null) {
if (path == null) {
setPath("/" + value);
} else {
if (path.endsWith("/")) {
setPath(path + encode(value));
} else {
setPath(path + "/" + encode(value));
}
}
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!