Class OptimizedCharsetDecoder
CharsetDecoder
behave like an
optimized CharsetDecoder.
The default implementations of the CharsetDecoder
s 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
-
Method Summary
Modifier and TypeMethodDescriptionfinal float
final Charset
charset()
final CharBuffer
decode
(ByteBuffer in) final CoderResult
decode
(ByteBuffer in, CharBuffer out, boolean endOfInput) boolean
final CoderResult
flush
(CharBuffer out) int
hashCode()
boolean
boolean
final float
final CharsetDecoder
onMalformedInput
(CodingErrorAction newAction) final CharsetDecoder
onUnmappableCharacter
(CodingErrorAction newAction) final String
final CharsetDecoder
replaceWith
(String newReplacement) final CharsetDecoder
reset()
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
-