39 |
39 |
40 /** |
40 /** |
41 * An engine that can transform a sequence of $itypesPhrase$ into a sequence of |
41 * An engine that can transform a sequence of $itypesPhrase$ into a sequence of |
42 * $otypesPhrase$. |
42 * $otypesPhrase$. |
43 * |
43 * |
44 * <a name="steps"> |
44 * <a name="steps"></a> |
45 * |
45 * |
46 * <p> The input $itype$ sequence is provided in a $itype$ buffer or a series |
46 * <p> The input $itype$ sequence is provided in a $itype$ buffer or a series |
47 * of such buffers. The output $otype$ sequence is written to a $otype$ buffer |
47 * of such buffers. The output $otype$ sequence is written to a $otype$ buffer |
48 * or a series of such buffers. $A$ $coder$ should always be used by making |
48 * or a series of such buffers. $A$ $coder$ should always be used by making |
49 * the following sequence of method invocations, hereinafter referred to as $a$ |
49 * the following sequence of method invocations, hereinafter referred to as $a$ |
74 * when $a$ $coding$ error has occurred. In each case a {@link CoderResult} |
74 * when $a$ $coding$ error has occurred. In each case a {@link CoderResult} |
75 * object is returned to describe the reason for termination. An invoker can |
75 * object is returned to describe the reason for termination. An invoker can |
76 * examine this object and fill the input buffer, flush the output buffer, or |
76 * examine this object and fill the input buffer, flush the output buffer, or |
77 * attempt to recover from $a$ $coding$ error, as appropriate, and try again. |
77 * attempt to recover from $a$ $coding$ error, as appropriate, and try again. |
78 * |
78 * |
79 * <a name="ce"> |
79 * <a name="ce"></a> |
80 * |
80 * |
81 * <p> There are two general types of $coding$ errors. If the input $itype$ |
81 * <p> There are two general types of $coding$ errors. If the input $itype$ |
82 * sequence is $notLegal$ then the input is considered <i>malformed</i>. If |
82 * sequence is $notLegal$ then the input is considered <i>malformed</i>. If |
83 * the input $itype$ sequence is legal but cannot be mapped to a valid |
83 * the input $itype$ sequence is legal but cannot be mapped to a valid |
84 * $outSequence$ then an <i>unmappable character</i> has been encountered. |
84 * $outSequence$ then an <i>unmappable character</i> has been encountered. |
85 * |
85 * |
86 * <a name="cae"> |
86 * <a name="cae"></a> |
87 * |
87 * |
88 * <p> How $a$ $coding$ error is handled depends upon the action requested for |
88 * <p> How $a$ $coding$ error is handled depends upon the action requested for |
89 * that type of error, which is described by an instance of the {@link |
89 * that type of error, which is described by an instance of the {@link |
90 * CodingErrorAction} class. The possible error actions are to {@link |
90 * CodingErrorAction} class. The possible error actions are to {@linkplain |
91 * CodingErrorAction#IGNORE </code>ignore<code>} the erroneous input, {@link |
91 * CodingErrorAction#IGNORE ignore} the erroneous input, {@linkplain |
92 * CodingErrorAction#REPORT </code>report<code>} the error to the invoker via |
92 * CodingErrorAction#REPORT report} the error to the invoker via |
93 * the returned {@link CoderResult} object, or {@link CodingErrorAction#REPLACE |
93 * the returned {@link CoderResult} object, or {@linkplain CodingErrorAction#REPLACE |
94 * </code>replace<code>} the erroneous input with the current value of the |
94 * replace} the erroneous input with the current value of the |
95 * replacement $replTypeName$. The replacement |
95 * replacement $replTypeName$. The replacement |
96 * |
96 * |
97 #if[encoder] |
97 #if[encoder] |
98 * is initially set to the $coder$'s default replacement, which often |
98 * is initially set to the $coder$'s default replacement, which often |
99 * (but not always) has the initial value $defaultReplName$; |
99 * (but not always) has the initial value $defaultReplName$; |
104 * |
104 * |
105 * its value may be changed via the {@link #replaceWith($replFQType$) |
105 * its value may be changed via the {@link #replaceWith($replFQType$) |
106 * replaceWith} method. |
106 * replaceWith} method. |
107 * |
107 * |
108 * <p> The default action for malformed-input and unmappable-character errors |
108 * <p> The default action for malformed-input and unmappable-character errors |
109 * is to {@link CodingErrorAction#REPORT </code>report<code>} them. The |
109 * is to {@linkplain CodingErrorAction#REPORT report} them. The |
110 * malformed-input error action may be changed via the {@link |
110 * malformed-input error action may be changed via the {@link |
111 * #onMalformedInput(CodingErrorAction) onMalformedInput} method; the |
111 * #onMalformedInput(CodingErrorAction) onMalformedInput} method; the |
112 * unmappable-character action may be changed via the {@link |
112 * unmappable-character action may be changed via the {@link |
113 * #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter} method. |
113 * #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter} method. |
114 * |
114 * |
175 * $otype$s that will be produced for each input $itype$ |
175 * $otype$s that will be produced for each input $itype$ |
176 * |
176 * |
177 * @param replacement |
177 * @param replacement |
178 * The initial replacement; must not be <tt>null</tt>, must have |
178 * The initial replacement; must not be <tt>null</tt>, must have |
179 * non-zero length, must not be longer than max$ItypesPerOtype$, |
179 * non-zero length, must not be longer than max$ItypesPerOtype$, |
180 * and must be {@link #isLegalReplacement </code>legal<code>} |
180 * and must be {@linkplain #isLegalReplacement legal} |
181 * |
181 * |
182 * @throws IllegalArgumentException |
182 * @throws IllegalArgumentException |
183 * If the preconditions on the parameters do not hold |
183 * If the preconditions on the parameters do not hold |
184 */ |
184 */ |
185 {#if[encoder]?protected:private} |
185 {#if[encoder]?protected:private} |
274 #end[decoder] |
274 #end[decoder] |
275 #if[encoder] |
275 #if[encoder] |
276 * The new replacement; must not be <tt>null</tt>, must have |
276 * The new replacement; must not be <tt>null</tt>, must have |
277 * non-zero length, must not be longer than the value returned by |
277 * non-zero length, must not be longer than the value returned by |
278 * the {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method, and |
278 * the {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method, and |
279 * must be {@link #isLegalReplacement </code>legal<code>} |
279 * must be {@link #isLegalReplacement legal} |
280 #end[encoder] |
280 #end[encoder] |
281 * |
281 * |
282 * @return This $coder$ |
282 * @return This $coder$ |
283 * |
283 * |
284 * @throws IllegalArgumentException |
284 * @throws IllegalArgumentException |
493 * This method should be invoked again with an output buffer that has |
493 * This method should be invoked again with an output buffer that has |
494 * more {@linkplain Buffer#remaining remaining} $otype$s. This is |
494 * more {@linkplain Buffer#remaining remaining} $otype$s. This is |
495 * typically done by draining any $code$d $otype$s from the output |
495 * typically done by draining any $code$d $otype$s from the output |
496 * buffer. </p></li> |
496 * buffer. </p></li> |
497 * |
497 * |
498 * <li><p> A {@link CoderResult#malformedForLength |
498 * <li><p> A {@linkplain CoderResult#malformedForLength |
499 * </code>malformed-input<code>} result indicates that a malformed-input |
499 * malformed-input} result indicates that a malformed-input |
500 * error has been detected. The malformed $itype$s begin at the input |
500 * error has been detected. The malformed $itype$s begin at the input |
501 * buffer's (possibly incremented) position; the number of malformed |
501 * buffer's (possibly incremented) position; the number of malformed |
502 * $itype$s may be determined by invoking the result object's {@link |
502 * $itype$s may be determined by invoking the result object's {@link |
503 * CoderResult#length() length} method. This case applies only if the |
503 * CoderResult#length() length} method. This case applies only if the |
504 * {@link #onMalformedInput </code>malformed action<code>} of this $coder$ |
504 * {@linkplain #onMalformedInput malformed action} of this $coder$ |
505 * is {@link CodingErrorAction#REPORT}; otherwise the malformed input |
505 * is {@link CodingErrorAction#REPORT}; otherwise the malformed input |
506 * will be ignored or replaced, as requested. </p></li> |
506 * will be ignored or replaced, as requested. </p></li> |
507 * |
507 * |
508 * <li><p> An {@link CoderResult#unmappableForLength |
508 * <li><p> An {@linkplain CoderResult#unmappableForLength |
509 * </code>unmappable-character<code>} result indicates that an |
509 * unmappable-character} result indicates that an |
510 * unmappable-character error has been detected. The $itype$s that |
510 * unmappable-character error has been detected. The $itype$s that |
511 * $code$ the unmappable character begin at the input buffer's (possibly |
511 * $code$ the unmappable character begin at the input buffer's (possibly |
512 * incremented) position; the number of such $itype$s may be determined |
512 * incremented) position; the number of such $itype$s may be determined |
513 * by invoking the result object's {@link CoderResult#length() length} |
513 * by invoking the result object's {@link CoderResult#length() length} |
514 * method. This case applies only if the {@link #onUnmappableCharacter |
514 * method. This case applies only if the {@linkplain #onUnmappableCharacter |
515 * </code>unmappable action<code>} of this $coder$ is {@link |
515 * unmappable action} of this $coder$ is {@link |
516 * CodingErrorAction#REPORT}; otherwise the unmappable character will be |
516 * CodingErrorAction#REPORT}; otherwise the unmappable character will be |
517 * ignored or replaced, as requested. </p></li> |
517 * ignored or replaced, as requested. </p></li> |
518 * |
518 * |
519 * </ul> |
519 * </ul> |
520 * |
520 * |