Package org.apache.tomcat.util.buf
Class UDecoder
- java.lang.Object
-
- org.apache.tomcat.util.buf.UDecoder
-
public final class UDecoder extends java.lang.Object
All URL decoding happens here. This way we can reuse, review, optimize without adding complexity to the buffers. The conversion will modify the original buffer.- Author:
- Costin Manolache
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
ALLOW_ENCODED_SLASH
-
Constructor Summary
Constructors Constructor Description UDecoder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
convert(java.lang.String str, boolean query)
%xx decoding of a string.void
convert(ByteChunk mb, boolean query)
URLDecode, will modify the source.void
convert(CharChunk mb, boolean query)
In-buffer processing - the buffer will be modified.void
convert(MessageBytes mb, boolean query)
URLDecode, will modify the sourcestatic java.lang.String
URLDecode(java.lang.String str)
Decode and return the specified URL-encoded String.static java.lang.String
URLDecode(java.lang.String str, java.nio.charset.Charset charset)
Decode and return the specified URL-encoded String.
-
-
-
Method Detail
-
convert
public void convert(ByteChunk mb, boolean query) throws java.io.IOException
URLDecode, will modify the source.- Parameters:
mb
- The URL encoded bytesquery
-true
if this is a query string- Throws:
java.io.IOException
- Invalid %xx URL encoding
-
convert
public void convert(CharChunk mb, boolean query) throws java.io.IOException
In-buffer processing - the buffer will be modified.- Parameters:
mb
- The URL encoded charsquery
-true
if this is a query string- Throws:
java.io.IOException
- Invalid %xx URL encoding
-
convert
public void convert(MessageBytes mb, boolean query) throws java.io.IOException
URLDecode, will modify the source- Parameters:
mb
- The URL encoded String, bytes or charsquery
-true
if this is a query string- Throws:
java.io.IOException
- Invalid %xx URL encoding
-
convert
public final java.lang.String convert(java.lang.String str, boolean query)
%xx decoding of a string. FIXME: this is inefficient.- Parameters:
str
- The URL encoded stringquery
-true
if this is a query string- Returns:
- the decoded string
-
URLDecode
public static java.lang.String URLDecode(java.lang.String str)
Decode and return the specified URL-encoded String. When the byte array is converted to a string, UTF-8 is used. This may be different than some other servers. It is assumed the string is not a query string.- Parameters:
str
- The url-encoded string- Returns:
- the decoded string
- Throws:
java.lang.IllegalArgumentException
- if a '%' character is not followed by a valid 2-digit hexadecimal number
-
URLDecode
public static java.lang.String URLDecode(java.lang.String str, java.nio.charset.Charset charset)
Decode and return the specified URL-encoded String. It is assumed the string is not a query string.- Parameters:
str
- The url-encoded stringcharset
- The character encoding to use; if null, UTF-8 is used.- Returns:
- the decoded string
- Throws:
java.lang.IllegalArgumentException
- if a '%' character is not followed by a valid 2-digit hexadecimal number
-
-