Class OptimizedCharsetDecoder
CharsetDecoder behave like an
optimized CharsetDecoder.
The default implementations of the CharsetDecoders in the JRE leave
data in the input buffer if there isn't sufficient data to decode the next
character. The invoker is expected to add more data to the input buffer in
response to the underflow result. This processing model can be used if you
have a single buffer that you fill using some source and drain using the
decoder.
If you use a model where one buffer is drained by the decoder while in
parallel another buffer is being filled by the source, this processing model
induces some difficulties, because an unknown number of bytes would have to
be copied over from the newly filled buffer to the previously decoded buffer.
This class provides what the documentation of
CharsetDecoder.decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer) calls an "optimized implementation". It
always drains the input buffer completely, caching any bytes that cannot be
decoded (yet) because they don't encode a complete character. When the
decode(ByteBuffer, CharBuffer, boolean) method is invoked for the
next time, as many bytes as needed to decode a complete character will be
added to the cached bytes and the now available character is appended to the
output. Then, the rest of the input is bulk processed as usual.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal floatfinal Charsetcharset()final CharBufferdecode(ByteBuffer in) final CoderResultdecode(ByteBuffer in, CharBuffer out, boolean endOfInput) booleanfinal CoderResultflush(CharBuffer out) inthashCode()booleanbooleanfinal floatfinal CharsetDecoderonMalformedInput(CodingErrorAction newAction) final CharsetDecoderonUnmappableCharacter(CodingErrorAction newAction) final Stringfinal CharsetDecoderreplaceWith(String newReplacement) final CharsetDecoderreset()toString()
-
Constructor Details
-
OptimizedCharsetDecoder
Creates a new instance.- Parameters:
backing- the backing charset decoder
-
-
Method Details
-
averageCharsPerByte
- Returns:
- the result
- See Also:
-
charset
- Returns:
- the result
- See Also:
-
decode
- Parameters:
in- the data to decodeout- the decoded dataendOfInput- true if the completes the input- Returns:
- the result
- See Also:
-
decode
- Parameters:
in- the data- Returns:
- the result
- Throws:
CharacterCodingException- if an error occurred- See Also:
-
detectedCharset
- Returns:
- the result
- See Also:
-
flush
- Parameters:
out- the decoded data- Returns:
- the result
- See Also:
-
isAutoDetecting
- Returns:
- the result
- See Also:
-
isCharsetDetected
- Returns:
- the result
- See Also:
-
malformedInputAction
- Returns:
- the result
- See Also:
-
maxCharsPerByte
- Returns:
- the result
- See Also:
-
onMalformedInput
- Parameters:
newAction- the action- Returns:
- the result
- See Also:
-
onUnmappableCharacter
- Parameters:
newAction- the action- Returns:
- the result
- See Also:
-
replaceWith
- Parameters:
newReplacement- the replacement- Returns:
- the result
- See Also:
-
replacement
- Returns:
- the result
- See Also:
-
reset
- Returns:
- the result
- See Also:
-
toString
-
unmappableCharacterAction
- Returns:
- the result
- See Also:
-
hashCode
-
equals
-