Package org.owasp.encoder
Class JavaEncoder
- java.lang.Object
-
- org.owasp.encoder.Encoder
-
- org.owasp.encoder.JavaEncoder
-
class JavaEncoder extends Encoder
JavaEncoder -- Encoder for Java based strings. Useful if in Java code generators to generate efficiently encoded strings for arbitrary data. This encoder uses the minimal sequence of characters required to encode a character (e.g. standard backslash escapes, such as "\n", "\\" , "\'", octal escapes, and unicode escapes). This encoder does NOT check UTF-16 surrogate pair sequences. The target output context supports mismatched UTF-16 pairs (e.g. it will compile, run, etc... with them).
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
OCT_ESCAPE_LENGTH
The length of a octal escape sequence, e.g.(package private) static int
OCT_MASK
The bit-mask for an octal unit.(package private) static int
OCT_SHIFT
Number of bits to shift for each octal unit.(package private) static int
U_ESCAPE_LENGTH
The length of a Unicode escape, e.g.
-
Constructor Summary
Constructors Constructor Description JavaEncoder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.nio.charset.CoderResult
encodeArrays(java.nio.CharBuffer input, java.nio.CharBuffer output, boolean endOfInput)
The core encoding loop used when both the input and output buffers are array backed.protected int
firstEncodedOffset(java.lang.String input, int off, int len)
Scans the input string for the first character index that requires encoding.protected int
maxEncodedLength(int n)
Returns the maximum encoded length (in chars) of an input sequence ofn
characters.-
Methods inherited from class org.owasp.encoder.Encoder
encode, encodeBuffers, overflow, underflow
-
-
-
-
Field Detail
-
U_ESCAPE_LENGTH
static final int U_ESCAPE_LENGTH
The length of a Unicode escape, e.g. "\\u1234".- See Also:
- Constant Field Values
-
OCT_ESCAPE_LENGTH
static final int OCT_ESCAPE_LENGTH
The length of a octal escape sequence, e.g. "\377".- See Also:
- Constant Field Values
-
OCT_SHIFT
static final int OCT_SHIFT
Number of bits to shift for each octal unit.- See Also:
- Constant Field Values
-
OCT_MASK
static final int OCT_MASK
The bit-mask for an octal unit.- See Also:
- Constant Field Values
-
-
Method Detail
-
maxEncodedLength
protected int maxEncodedLength(int n)
Description copied from class:Encoder
Returns the maximum encoded length (in chars) of an input sequence ofn
characters.- Specified by:
maxEncodedLength
in classEncoder
- Parameters:
n
- the number of characters of input- Returns:
- the worst-case number of characters required to encode
-
firstEncodedOffset
protected int firstEncodedOffset(java.lang.String input, int off, int len)
Description copied from class:Encoder
Scans the input string for the first character index that requires encoding. If the entire input does not require encoding then the length is returned. This method is used by the Encode.forXYZ methods to return input strings unchanged when possible.- Specified by:
firstEncodedOffset
in classEncoder
- Parameters:
input
- the input to check for encodingoff
- the offset of the first character to checklen
- the number of characters to check- Returns:
- the index of the first character to encode. The return value
will be
off+len
if no characters in the input require encoding.
-
encodeArrays
protected java.nio.charset.CoderResult encodeArrays(java.nio.CharBuffer input, java.nio.CharBuffer output, boolean endOfInput)
Description copied from class:Encoder
The core encoding loop used when both the input and output buffers are array backed. The loop is expected to fetch the arrays and interact with the arrays directly for performance.- Overrides:
encodeArrays
in classEncoder
- Parameters:
input
- the input buffer.output
- the output buffer.endOfInput
- when true, this is the last input to encode- Returns:
- UNDERFLOW or OVERFLOW
-
-