下面列出了org.springframework.util.StringUtils#uriDecode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Mono<Resource> apply(ServerRequest request) {
PathContainer pathContainer = request.pathContainer();
if (!this.pattern.matches(pathContainer)) {
return Mono.empty();
}
pathContainer = this.pattern.extractPathWithinPattern(pathContainer);
String path = processPath(pathContainer.value());
if (path.contains("%")) {
path = StringUtils.uriDecode(path, StandardCharsets.UTF_8);
}
if (!StringUtils.hasLength(path) || isInvalidPath(path)) {
return Mono.empty();
}
try {
Resource resource = this.location.createRelative(path);
if (resource.exists() && resource.isReadable() && isResourceUnderLocation(resource)) {
return Mono.just(resource);
}
else {
return Mono.empty();
}
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
@Override
public Optional<Resource> apply(ServerRequest request) {
PathContainer pathContainer = request.pathContainer();
if (!this.pattern.matches(pathContainer)) {
return Optional.empty();
}
pathContainer = this.pattern.extractPathWithinPattern(pathContainer);
String path = processPath(pathContainer.value());
if (path.contains("%")) {
path = StringUtils.uriDecode(path, StandardCharsets.UTF_8);
}
if (!StringUtils.hasLength(path) || isInvalidPath(path)) {
return Optional.empty();
}
try {
Resource resource = this.location.createRelative(path);
if (resource.exists() && resource.isReadable() && isResourceUnderLocation(resource)) {
return Optional.of(resource);
}
else {
return Optional.empty();
}
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
@Override
public Mono<Resource> apply(ServerRequest request) {
PathContainer pathContainer = request.pathContainer();
if (!this.pattern.matches(pathContainer)) {
return Mono.empty();
}
pathContainer = this.pattern.extractPathWithinPattern(pathContainer);
String path = processPath(pathContainer.value());
if (path.contains("%")) {
path = StringUtils.uriDecode(path, StandardCharsets.UTF_8);
}
if (!StringUtils.hasLength(path) || isInvalidPath(path)) {
return Mono.empty();
}
try {
Resource resource = this.location.createRelative(path);
if (resource.exists() && resource.isReadable() && isResourceUnderLocation(resource)) {
return Mono.just(resource);
}
else {
return Mono.empty();
}
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
/**
* url 解码
*
* @param source the encoded String
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String urlDecode(String source) {
return StringUtils.uriDecode(source, Charsets.UTF_8);
}
/**
* url 解码
*
* @param source the encoded String
* @param charset the character encoding to use
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String urlDecode(String source, Charset charset) {
return StringUtils.uriDecode(source, charset);
}
/**
* Decode the given encoded URI component.
* <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules.
* @param source the encoded String
* @param encoding the character encoding to use
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String decode(String source, String encoding) {
return StringUtils.uriDecode(source, Charset.forName(encoding));
}
/**
* Decode the given encoded URI component.
* <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules.
* @param source the encoded String
* @param charset the character encoding to use
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @since 5.0
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String decode(String source, Charset charset) {
return StringUtils.uriDecode(source, charset);
}
/**
* Decode the given encoded URI component.
* <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules.
* @param source the encoded String
* @param encoding the character encoding to use
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String decode(String source, String encoding) {
return StringUtils.uriDecode(source, Charset.forName(encoding));
}
/**
* Decode the given encoded URI component.
* <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules.
* @param source the encoded String
* @param charset the character encoding to use
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @since 5.0
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String decode(String source, Charset charset) {
return StringUtils.uriDecode(source, charset);
}
/**
* Decode the given encoded URI component.
* <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules.
*
* @param source the encoded String
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String decode(String source) {
return StringUtils.uriDecode(source, Charsets.UTF_8);
}
/**
* Decode the given encoded URI component.
* <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules.
*
* @param source the encoded String
* @param charset the character encoding to use
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String decode(String source, Charset charset) {
return StringUtils.uriDecode(source, charset);
}