53 * |
53 * |
54 * <li><p> Reset the $coder$ via the {@link #reset reset} method, unless it |
54 * <li><p> Reset the $coder$ via the {@link #reset reset} method, unless it |
55 * has not been used before; </p></li> |
55 * has not been used before; </p></li> |
56 * |
56 * |
57 * <li><p> Invoke the {@link #$code$ $code$} method zero or more times, as |
57 * <li><p> Invoke the {@link #$code$ $code$} method zero or more times, as |
58 * long as additional input may be available, passing <tt>false</tt> for the |
58 * long as additional input may be available, passing {@code false} for the |
59 * <tt>endOfInput</tt> argument and filling the input buffer and flushing the |
59 * {@code endOfInput} argument and filling the input buffer and flushing the |
60 * output buffer between invocations; </p></li> |
60 * output buffer between invocations; </p></li> |
61 * |
61 * |
62 * <li><p> Invoke the {@link #$code$ $code$} method one final time, passing |
62 * <li><p> Invoke the {@link #$code$ $code$} method one final time, passing |
63 * <tt>true</tt> for the <tt>endOfInput</tt> argument; and then </p></li> |
63 * {@code true} for the {@code endOfInput} argument; and then </p></li> |
64 * |
64 * |
65 * <li><p> Invoke the {@link #flush flush} method so that the $coder$ can |
65 * <li><p> Invoke the {@link #flush flush} method so that the $coder$ can |
66 * flush any internal state to the output buffer. </p></li> |
66 * flush any internal state to the output buffer. </p></li> |
67 * |
67 * |
68 * </ol> |
68 * </ol> |
173 * @param max$ItypesPerOtype$ |
173 * @param max$ItypesPerOtype$ |
174 * A positive float value indicating the maximum number of |
174 * A positive float value indicating the maximum number of |
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 {@code null}, 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 {@linkplain #isLegalReplacement legal} |
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 |
265 * <p> This method invokes the {@link #implReplaceWith implReplaceWith} |
265 * <p> This method invokes the {@link #implReplaceWith implReplaceWith} |
266 * method, passing the new replacement, after checking that the new |
266 * method, passing the new replacement, after checking that the new |
267 * replacement is acceptable. </p> |
267 * replacement is acceptable. </p> |
268 * |
268 * |
269 * @param newReplacement The new replacement; must not be |
269 * @param newReplacement The new replacement; must not be |
270 * <tt>null</tt>, must have non-zero length, |
270 * {@code null}, must have non-zero length, |
271 #if[decoder] |
271 #if[decoder] |
272 * and must not be longer than the value returned by the |
272 * and must not be longer than the value returned by the |
273 * {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method |
273 * {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method |
274 #end[decoder] |
274 #end[decoder] |
275 #if[encoder] |
275 #if[encoder] |
330 * <p> The default implementation of this method is not very efficient; it |
330 * <p> The default implementation of this method is not very efficient; it |
331 * should generally be overridden to improve performance. </p> |
331 * should generally be overridden to improve performance. </p> |
332 * |
332 * |
333 * @param repl The byte array to be tested |
333 * @param repl The byte array to be tested |
334 * |
334 * |
335 * @return <tt>true</tt> if, and only if, the given byte array |
335 * @return {@code true} if, and only if, the given byte array |
336 * is a legal replacement value for this encoder |
336 * is a legal replacement value for this encoder |
337 */ |
337 */ |
338 public boolean isLegalReplacement(byte[] repl) { |
338 public boolean isLegalReplacement(byte[] repl) { |
339 WeakReference<CharsetDecoder> wr = cachedDecoder; |
339 WeakReference<CharsetDecoder> wr = cachedDecoder; |
340 CharsetDecoder dec = null; |
340 CharsetDecoder dec = null; |
368 * Changes this $coder$'s action for malformed-input errors. |
368 * Changes this $coder$'s action for malformed-input errors. |
369 * |
369 * |
370 * <p> This method invokes the {@link #implOnMalformedInput |
370 * <p> This method invokes the {@link #implOnMalformedInput |
371 * implOnMalformedInput} method, passing the new action. </p> |
371 * implOnMalformedInput} method, passing the new action. </p> |
372 * |
372 * |
373 * @param newAction The new action; must not be <tt>null</tt> |
373 * @param newAction The new action; must not be {@code null} |
374 * |
374 * |
375 * @return This $coder$ |
375 * @return This $coder$ |
376 * |
376 * |
377 * @throws IllegalArgumentException |
377 * @throws IllegalArgumentException |
378 * If the precondition on the parameter does not hold |
378 * If the precondition on the parameter does not hold |
410 * Changes this $coder$'s action for unmappable-character errors. |
410 * Changes this $coder$'s action for unmappable-character errors. |
411 * |
411 * |
412 * <p> This method invokes the {@link #implOnUnmappableCharacter |
412 * <p> This method invokes the {@link #implOnUnmappableCharacter |
413 * implOnUnmappableCharacter} method, passing the new action. </p> |
413 * implOnUnmappableCharacter} method, passing the new action. </p> |
414 * |
414 * |
415 * @param newAction The new action; must not be <tt>null</tt> |
415 * @param newAction The new action; must not be {@code null} |
416 * |
416 * |
417 * @return This $coder$ |
417 * @return This $coder$ |
418 * |
418 * |
419 * @throws IllegalArgumentException |
419 * @throws IllegalArgumentException |
420 * If the precondition on the parameter does not hold |
420 * If the precondition on the parameter does not hold |
519 * |
519 * |
520 * In any case, if this method is to be reinvoked in the same $coding$ |
520 * In any case, if this method is to be reinvoked in the same $coding$ |
521 * operation then care should be taken to preserve any $itype$s remaining |
521 * operation then care should be taken to preserve any $itype$s remaining |
522 * in the input buffer so that they are available to the next invocation. |
522 * in the input buffer so that they are available to the next invocation. |
523 * |
523 * |
524 * <p> The <tt>endOfInput</tt> parameter advises this method as to whether |
524 * <p> The {@code endOfInput} parameter advises this method as to whether |
525 * the invoker can provide further input beyond that contained in the given |
525 * the invoker can provide further input beyond that contained in the given |
526 * input buffer. If there is a possibility of providing additional input |
526 * input buffer. If there is a possibility of providing additional input |
527 * then the invoker should pass <tt>false</tt> for this parameter; if there |
527 * then the invoker should pass {@code false} for this parameter; if there |
528 * is no possibility of providing further input then the invoker should |
528 * is no possibility of providing further input then the invoker should |
529 * pass <tt>true</tt>. It is not erroneous, and in fact it is quite |
529 * pass {@code true}. It is not erroneous, and in fact it is quite |
530 * common, to pass <tt>false</tt> in one invocation and later discover that |
530 * common, to pass {@code false} in one invocation and later discover that |
531 * no further input was actually available. It is critical, however, that |
531 * no further input was actually available. It is critical, however, that |
532 * the final invocation of this method in a sequence of invocations always |
532 * the final invocation of this method in a sequence of invocations always |
533 * pass <tt>true</tt> so that any remaining un$code$d input will be treated |
533 * pass {@code true} so that any remaining un$code$d input will be treated |
534 * as being malformed. |
534 * as being malformed. |
535 * |
535 * |
536 * <p> This method works by invoking the {@link #$code$Loop $code$Loop} |
536 * <p> This method works by invoking the {@link #$code$Loop $code$Loop} |
537 * method, interpreting its results, handling error conditions, and |
537 * method, interpreting its results, handling error conditions, and |
538 * reinvoking it as necessary. </p> |
538 * reinvoking it as necessary. </p> |
543 * |
543 * |
544 * @param out |
544 * @param out |
545 * The output $otype$ buffer |
545 * The output $otype$ buffer |
546 * |
546 * |
547 * @param endOfInput |
547 * @param endOfInput |
548 * <tt>true</tt> if, and only if, the invoker can provide no |
548 * {@code true} if, and only if, the invoker can provide no |
549 * additional input $itype$s beyond those in the given buffer |
549 * additional input $itype$s beyond those in the given buffer |
550 * |
550 * |
551 * @return A coder-result object describing the reason for termination |
551 * @return A coder-result object describing the reason for termination |
552 * |
552 * |
553 * @throws IllegalStateException |
553 * @throws IllegalStateException |
554 * If $a$ $coding$ operation is already in progress and the previous |
554 * If $a$ $coding$ operation is already in progress and the previous |
555 * step was an invocation neither of the {@link #reset reset} |
555 * step was an invocation neither of the {@link #reset reset} |
556 * method, nor of this method with a value of <tt>false</tt> for |
556 * method, nor of this method with a value of {@code false} for |
557 * the <tt>endOfInput</tt> parameter, nor of this method with a |
557 * the {@code endOfInput} parameter, nor of this method with a |
558 * value of <tt>true</tt> for the <tt>endOfInput</tt> parameter |
558 * value of {@code true} for the {@code endOfInput} parameter |
559 * but a return value indicating an incomplete $coding$ operation |
559 * but a return value indicating an incomplete $coding$ operation |
560 * |
560 * |
561 * @throws CoderMalfunctionError |
561 * @throws CoderMalfunctionError |
562 * If an invocation of the $code$Loop method threw |
562 * If an invocation of the $code$Loop method threw |
563 * an unexpected exception |
563 * an unexpected exception |
657 * @throws IllegalStateException |
657 * @throws IllegalStateException |
658 * If the previous step of the current $coding$ operation was an |
658 * If the previous step of the current $coding$ operation was an |
659 * invocation neither of the {@link #flush flush} method nor of |
659 * invocation neither of the {@link #flush flush} method nor of |
660 * the three-argument {@link |
660 * the three-argument {@link |
661 * #$code$($Itype$Buffer,$Otype$Buffer,boolean) $code$} method |
661 * #$code$($Itype$Buffer,$Otype$Buffer,boolean) $code$} method |
662 * with a value of <tt>true</tt> for the <tt>endOfInput</tt> |
662 * with a value of {@code true} for the {@code endOfInput} |
663 * parameter |
663 * parameter |
664 */ |
664 */ |
665 public final CoderResult flush($Otype$Buffer out) { |
665 public final CoderResult flush($Otype$Buffer out) { |
666 if (state == ST_END) { |
666 if (state == ST_END) { |
667 CoderResult cr = implFlush(out); |
667 CoderResult cr = implFlush(out); |
822 |
822 |
823 /** |
823 /** |
824 * Tells whether or not this decoder implements an auto-detecting charset. |
824 * Tells whether or not this decoder implements an auto-detecting charset. |
825 * |
825 * |
826 * <p> The default implementation of this method always returns |
826 * <p> The default implementation of this method always returns |
827 * <tt>false</tt>; it should be overridden by auto-detecting decoders to |
827 * {@code false}; it should be overridden by auto-detecting decoders to |
828 * return <tt>true</tt>. </p> |
828 * return {@code true}. </p> |
829 * |
829 * |
830 * @return <tt>true</tt> if, and only if, this decoder implements an |
830 * @return {@code true} if, and only if, this decoder implements an |
831 * auto-detecting charset |
831 * auto-detecting charset |
832 */ |
832 */ |
833 public boolean isAutoDetecting() { |
833 public boolean isAutoDetecting() { |
834 return false; |
834 return false; |
835 } |
835 } |
838 * Tells whether or not this decoder has yet detected a |
838 * Tells whether or not this decoder has yet detected a |
839 * charset <i>(optional operation)</i>. |
839 * charset <i>(optional operation)</i>. |
840 * |
840 * |
841 * <p> If this decoder implements an auto-detecting charset then at a |
841 * <p> If this decoder implements an auto-detecting charset then at a |
842 * single point during a decoding operation this method may start returning |
842 * single point during a decoding operation this method may start returning |
843 * <tt>true</tt> to indicate that a specific charset has been detected in |
843 * {@code true} to indicate that a specific charset has been detected in |
844 * the input byte sequence. Once this occurs, the {@link #detectedCharset |
844 * the input byte sequence. Once this occurs, the {@link #detectedCharset |
845 * detectedCharset} method may be invoked to retrieve the detected charset. |
845 * detectedCharset} method may be invoked to retrieve the detected charset. |
846 * |
846 * |
847 * <p> That this method returns <tt>false</tt> does not imply that no bytes |
847 * <p> That this method returns {@code false} does not imply that no bytes |
848 * have yet been decoded. Some auto-detecting decoders are capable of |
848 * have yet been decoded. Some auto-detecting decoders are capable of |
849 * decoding some, or even all, of an input byte sequence without fixing on |
849 * decoding some, or even all, of an input byte sequence without fixing on |
850 * a particular charset. |
850 * a particular charset. |
851 * |
851 * |
852 * <p> The default implementation of this method always throws an {@link |
852 * <p> The default implementation of this method always throws an {@link |
853 * UnsupportedOperationException}; it should be overridden by |
853 * UnsupportedOperationException}; it should be overridden by |
854 * auto-detecting decoders to return <tt>true</tt> once the input charset |
854 * auto-detecting decoders to return {@code true} once the input charset |
855 * has been determined. </p> |
855 * has been determined. </p> |
856 * |
856 * |
857 * @return <tt>true</tt> if, and only if, this decoder has detected a |
857 * @return {@code true} if, and only if, this decoder has detected a |
858 * specific charset |
858 * specific charset |
859 * |
859 * |
860 * @throws UnsupportedOperationException |
860 * @throws UnsupportedOperationException |
861 * If this decoder does not implement an auto-detecting charset |
861 * If this decoder does not implement an auto-detecting charset |
862 */ |
862 */ |
878 * <p> The default implementation of this method always throws an {@link |
878 * <p> The default implementation of this method always throws an {@link |
879 * UnsupportedOperationException}; it should be overridden by |
879 * UnsupportedOperationException}; it should be overridden by |
880 * auto-detecting decoders to return the appropriate value. </p> |
880 * auto-detecting decoders to return the appropriate value. </p> |
881 * |
881 * |
882 * @return The charset detected by this auto-detecting decoder, |
882 * @return The charset detected by this auto-detecting decoder, |
883 * or <tt>null</tt> if the charset has not yet been determined |
883 * or {@code null} if the charset has not yet been determined |
884 * |
884 * |
885 * @throws IllegalStateException |
885 * @throws IllegalStateException |
886 * If insufficient bytes have been read to determine a charset |
886 * If insufficient bytes have been read to determine a charset |
887 * |
887 * |
888 * @throws UnsupportedOperationException |
888 * @throws UnsupportedOperationException |
918 } |
918 } |
919 |
919 |
920 /** |
920 /** |
921 * Tells whether or not this encoder can encode the given character. |
921 * Tells whether or not this encoder can encode the given character. |
922 * |
922 * |
923 * <p> This method returns <tt>false</tt> if the given character is a |
923 * <p> This method returns {@code false} if the given character is a |
924 * surrogate character; such characters can be interpreted only when they |
924 * surrogate character; such characters can be interpreted only when they |
925 * are members of a pair consisting of a high surrogate followed by a low |
925 * are members of a pair consisting of a high surrogate followed by a low |
926 * surrogate. The {@link #canEncode(java.lang.CharSequence) |
926 * surrogate. The {@link #canEncode(java.lang.CharSequence) |
927 * canEncode(CharSequence)} method may be used to test whether or not a |
927 * canEncode(CharSequence)} method may be used to test whether or not a |
928 * character sequence can be encoded. |
928 * character sequence can be encoded. |
935 * should generally be overridden to improve performance. </p> |
935 * should generally be overridden to improve performance. </p> |
936 * |
936 * |
937 * @param c |
937 * @param c |
938 * The given character |
938 * The given character |
939 * |
939 * |
940 * @return <tt>true</tt> if, and only if, this encoder can encode |
940 * @return {@code true} if, and only if, this encoder can encode |
941 * the given character |
941 * the given character |
942 * |
942 * |
943 * @throws IllegalStateException |
943 * @throws IllegalStateException |
944 * If $a$ $coding$ operation is already in progress |
944 * If $a$ $coding$ operation is already in progress |
945 */ |
945 */ |
952 |
952 |
953 /** |
953 /** |
954 * Tells whether or not this encoder can encode the given character |
954 * Tells whether or not this encoder can encode the given character |
955 * sequence. |
955 * sequence. |
956 * |
956 * |
957 * <p> If this method returns <tt>false</tt> for a particular character |
957 * <p> If this method returns {@code false} for a particular character |
958 * sequence then more information about why the sequence cannot be encoded |
958 * sequence then more information about why the sequence cannot be encoded |
959 * may be obtained by performing a full <a href="#steps">encoding |
959 * may be obtained by performing a full <a href="#steps">encoding |
960 * operation</a>. |
960 * operation</a>. |
961 * |
961 * |
962 * <p> This method may modify this encoder's state; it should therefore not |
962 * <p> This method may modify this encoder's state; it should therefore not |
966 * should generally be overridden to improve performance. </p> |
966 * should generally be overridden to improve performance. </p> |
967 * |
967 * |
968 * @param cs |
968 * @param cs |
969 * The given character sequence |
969 * The given character sequence |
970 * |
970 * |
971 * @return <tt>true</tt> if, and only if, this encoder can encode |
971 * @return {@code true} if, and only if, this encoder can encode |
972 * the given character without throwing any exceptions and without |
972 * the given character without throwing any exceptions and without |
973 * performing any replacements |
973 * performing any replacements |
974 * |
974 * |
975 * @throws IllegalStateException |
975 * @throws IllegalStateException |
976 * If $a$ $coding$ operation is already in progress |
976 * If $a$ $coding$ operation is already in progress |