Top Description Inners Fields Constructors Methods
org.apache.tomcat.util.buf

public final Class UDecoder

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .CharConversionException, .IOException, .OutputStreamWriter, java.nio.charset.Charset, .StandardCharsets, org.apache.tomcat.util.res.StringManager

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final IOException
EXCEPTION_EOF

Unexpected end of data.

private static final IOException
EXCEPTION_NOT_HEX_DIGIT

%xx with not-hex digit

private static final IOException
EXCEPTION_SLASH

%-encoded slash is forbidden in resource path

private static final StringManager

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
convert(ByteChunk
The URL encoded bytes
mb
,
boolean
true if this is a query string. For a query string '+' will be decoded to ' '
query
)

URLDecode, will modify the source.

public void
convert(ByteChunk
The URL encoded bytes
mb
,
EncodedSolidusHandling
How should the %2f sequence handled by the decoder? For query strings this parameter will be ignored and the %2f sequence will be decoded
encodedSolidusHandling
)

URLDecode, will modify the source.

private void
convert(ByteChunk mb, boolean query, EncodedSolidusHandling encodedSolidusHandling)

private static boolean
isHexDigit(int c)

public static String

Returns:

the decoded string
URLDecode
(String
The url-encoded string
str
,
Charset
The character encoding to use; if null, UTF-8 is used.
charset
)

Decode and return the specified URL-encoded String.

private static int
x2c(byte b1, byte b2)

private static int
x2c(char b1, char b2)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EXCEPTION_EOFback to summary
private static final IOException EXCEPTION_EOF

Unexpected end of data.

EXCEPTION_NOT_HEX_DIGITback to summary
private static final IOException EXCEPTION_NOT_HEX_DIGIT

%xx with not-hex digit

EXCEPTION_SLASHback to summary
private static final IOException EXCEPTION_SLASH

%-encoded slash is forbidden in resource path

smback to summary
private static final StringManager sm

Constructor Detail

UDecoderback to summary
public UDecoder()

Method Detail

convertback to summary
public void convert(ByteChunk mb, boolean query) throws IOException

URLDecode, will modify the source. Assumes source bytes are encoded using a superset of US-ASCII as per RFC 7230. "%2f" will be rejected unless the input is a query string.

Parameters
mb:ByteChunk

The URL encoded bytes

query:boolean

true if this is a query string. For a query string '+' will be decoded to ' '

Exceptions
IOException:
Invalid %xx URL encoding
convertback to summary
public void convert(ByteChunk mb, EncodedSolidusHandling encodedSolidusHandling) throws IOException

URLDecode, will modify the source. Assumes source bytes are encoded using a superset of US-ASCII as per RFC 7230.

Parameters
mb:ByteChunk

The URL encoded bytes

encodedSolidusHandling:EncodedSolidusHandling

How should the %2f sequence handled by the decoder? For query strings this parameter will be ignored and the %2f sequence will be decoded

Exceptions
IOException:
Invalid %xx URL encoding
convertback to summary
private void convert(ByteChunk mb, boolean query, EncodedSolidusHandling encodedSolidusHandling) throws IOException
isHexDigitback to summary
private static boolean isHexDigit(int c)
URLDecodeback to summary
public static String URLDecode(String str, Charset charset)

Decode and return the specified URL-encoded String. It is assumed the string is not a query string.

Parameters
str:String

The url-encoded string

charset:Charset

The character encoding to use; if null, UTF-8 is used.

Returns:String

the decoded string

Exceptions
IllegalArgumentException:
if a '%' character is not followed by a valid 2-digit hexadecimal number
x2cback to summary
private static int x2c(byte b1, byte b2)
x2cback to summary
private static int x2c(char b1, char b2)
org.apache.tomcat.util.buf back to summary

private Class UDecoder.DecodeException

extends CharConversionException
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public synchronized Throwable
fillInStackTrace()

Overrides java.lang.Throwable.fillInStackTrace.

Fills in the execution stack trace.

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.io.CharConversionException.serialVersionUID.

Constructor Detail

DecodeExceptionback to summary
pack-priv DecodeException(String s)

Method Detail

fillInStackTraceback to summary
public synchronized Throwable fillInStackTrace()

Overrides java.lang.Throwable.fillInStackTrace.

Doc from java.lang.Throwable.fillInStackTrace.

Fills in the execution stack trace. This method records within this Throwable object information about the current state of the stack frames for the current thread.

If the stack trace of this Throwable is not writable, calling this method has no effect.

Returns:Throwable

a reference to this Throwable instance.

Annotations
@Override