2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26 // -- This file was mechanically generated: Do not edit! -- //
28 package java.nio.charset;
30 //import java.nio.Buffer;
31 //import java.nio.ByteBuffer;
32 //import java.nio.CharBuffer;
33 //import java.nio.BufferOverflowException;
34 //import java.nio.BufferUnderflowException;
35 import java.lang.ref.WeakReference;
36 //import java.nio.charset.CoderMalfunctionError; // javadoc
40 * An engine that can transform a sequence of bytes in a specific charset into a sequence of
41 * sixteen-bit Unicode characters.
45 * <p> The input byte sequence is provided in a byte buffer or a series
46 * of such buffers. The output character sequence is written to a character buffer
47 * or a series of such buffers. A decoder should always be used by making
48 * the following sequence of method invocations, hereinafter referred to as a
49 * <i>decoding operation</i>:
53 * <li><p> Reset the decoder via the {@link #reset reset} method, unless it
54 * has not been used before; </p></li>
56 * <li><p> Invoke the {@link #decode decode} method zero or more times, as
57 * long as additional input may be available, passing <tt>false</tt> for the
58 * <tt>endOfInput</tt> argument and filling the input buffer and flushing the
59 * output buffer between invocations; </p></li>
61 * <li><p> Invoke the {@link #decode decode} method one final time, passing
62 * <tt>true</tt> for the <tt>endOfInput</tt> argument; and then </p></li>
64 * <li><p> Invoke the {@link #flush flush} method so that the decoder can
65 * flush any internal state to the output buffer. </p></li>
69 * Each invocation of the {@link #decode decode} method will decode as many
70 * bytes as possible from the input buffer, writing the resulting characters
71 * to the output buffer. The {@link #decode decode} method returns when more
72 * input is required, when there is not enough room in the output buffer, or
73 * when a decoding error has occurred. In each case a {@link CoderResult}
74 * object is returned to describe the reason for termination. An invoker can
75 * examine this object and fill the input buffer, flush the output buffer, or
76 * attempt to recover from a decoding error, as appropriate, and try again.
80 * <p> There are two general types of decoding errors. If the input byte
81 * sequence is not legal for this charset then the input is considered <i>malformed</i>. If
82 * the input byte sequence is legal but cannot be mapped to a valid
83 * Unicode character then an <i>unmappable character</i> has been encountered.
87 * <p> How a decoding error is handled depends upon the action requested for
88 * that type of error, which is described by an instance of the {@link
89 * CodingErrorAction} class. The possible error actions are to {@link
90 * CodingErrorAction#IGNORE </code>ignore<code>} the erroneous input, {@link
91 * CodingErrorAction#REPORT </code>report<code>} the error to the invoker via
92 * the returned {@link CoderResult} object, or {@link CodingErrorAction#REPLACE
93 * </code>replace<code>} the erroneous input with the current value of the
94 * replacement string. The replacement
101 * has the initial value <tt>"\uFFFD"</tt>;
104 * its value may be changed via the {@link #replaceWith(java.lang.String)
105 * replaceWith} method.
107 * <p> The default action for malformed-input and unmappable-character errors
108 * is to {@link CodingErrorAction#REPORT </code>report<code>} them. The
109 * malformed-input error action may be changed via the {@link
110 * #onMalformedInput(CodingErrorAction) onMalformedInput} method; the
111 * unmappable-character action may be changed via the {@link
112 * #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter} method.
114 * <p> This class is designed to handle many of the details of the decoding
115 * process, including the implementation of error actions. A decoder for a
116 * specific charset, which is a concrete subclass of this class, need only
117 * implement the abstract {@link #decodeLoop decodeLoop} method, which
118 * encapsulates the basic decoding loop. A subclass that maintains internal
119 * state should, additionally, override the {@link #implFlush implFlush} and
120 * {@link #implReset implReset} methods.
122 * <p> Instances of this class are not safe for use by multiple concurrent
126 * @author Mark Reinhold
127 * @author JSR-51 Expert Group
133 * @see CharsetEncoder
136 public abstract class CharsetDecoder {
138 private final Charset charset;
139 private final float averageCharsPerByte;
140 private final float maxCharsPerByte;
142 private String replacement;
143 // private CodingErrorAction malformedInputAction
144 // = CodingErrorAction.REPORT;
145 // private CodingErrorAction unmappableCharacterAction
146 // = CodingErrorAction.REPORT;
150 private static final int ST_RESET = 0;
151 private static final int ST_CODING = 1;
152 private static final int ST_END = 2;
153 private static final int ST_FLUSHED = 3;
155 private int state = ST_RESET;
157 private static String stateNames[]
158 = { "RESET", "CODING", "CODING_END", "FLUSHED" };
162 * Initializes a new decoder. The new decoder will have the given
163 * chars-per-byte and replacement values. </p>
165 * @param averageCharsPerByte
166 * A positive float value indicating the expected number of
167 * characters that will be produced for each input byte
169 * @param maxCharsPerByte
170 * A positive float value indicating the maximum number of
171 * characters that will be produced for each input byte
174 * The initial replacement; must not be <tt>null</tt>, must have
175 * non-zero length, must not be longer than maxCharsPerByte,
176 * and must be {@link #isLegalReplacement </code>legal<code>}
178 * @throws IllegalArgumentException
179 * If the preconditions on the parameters do not hold
182 CharsetDecoder(Charset cs,
183 float averageCharsPerByte,
184 float maxCharsPerByte,
188 if (averageCharsPerByte <= 0.0f)
189 throw new IllegalArgumentException("Non-positive "
190 + "averageCharsPerByte");
191 if (maxCharsPerByte <= 0.0f)
192 throw new IllegalArgumentException("Non-positive "
193 + "maxCharsPerByte");
194 if (averageCharsPerByte > maxCharsPerByte)
195 throw new IllegalArgumentException("averageCharsPerByte"
197 + "maxCharsPerByte");
198 this.replacement = replacement;
199 this.averageCharsPerByte = averageCharsPerByte;
200 this.maxCharsPerByte = maxCharsPerByte;
201 replaceWith(replacement);
205 * Initializes a new decoder. The new decoder will have the given
206 * chars-per-byte values and its replacement will be the
207 * string <tt>"\uFFFD"</tt>. </p>
209 * @param averageCharsPerByte
210 * A positive float value indicating the expected number of
211 * characters that will be produced for each input byte
213 * @param maxCharsPerByte
214 * A positive float value indicating the maximum number of
215 * characters that will be produced for each input byte
217 * @throws IllegalArgumentException
218 * If the preconditions on the parameters do not hold
220 protected CharsetDecoder(Charset cs,
221 float averageCharsPerByte,
222 float maxCharsPerByte)
225 averageCharsPerByte, maxCharsPerByte,
230 * Returns the charset that created this decoder. </p>
232 * @return This decoder's charset
234 public final Charset charset() {
239 * Returns this decoder's replacement value. </p>
241 * @return This decoder's current replacement,
242 * which is never <tt>null</tt> and is never empty
244 public final String replacement() {
249 * Changes this decoder's replacement value.
251 * <p> This method invokes the {@link #implReplaceWith implReplaceWith}
252 * method, passing the new replacement, after checking that the new
253 * replacement is acceptable. </p>
255 * @param newReplacement
258 * The new replacement; must not be <tt>null</tt>
259 * and must have non-zero length
268 * @return This decoder
270 * @throws IllegalArgumentException
271 * If the preconditions on the parameter do not hold
273 public final CharsetDecoder replaceWith(String newReplacement) {
274 if (newReplacement == null)
275 throw new IllegalArgumentException("Null replacement");
276 int len = newReplacement.length();
278 throw new IllegalArgumentException("Empty replacement");
279 if (len > maxCharsPerByte)
280 throw new IllegalArgumentException("Replacement too long");
285 this.replacement = newReplacement;
286 implReplaceWith(newReplacement);
291 * Reports a change to this decoder's replacement value.
293 * <p> The default implementation of this method does nothing. This method
294 * should be overridden by decoders that require notification of changes to
295 * the replacement. </p>
297 * @param newReplacement
299 protected void implReplaceWith(String newReplacement) {
343 * Returns this decoder's current action for malformed-input errors. </p>
345 * @return The current malformed-input action, which is never <tt>null</tt>
347 // public CodingErrorAction malformedInputAction() {
348 // return malformedInputAction;
352 * Changes this decoder's action for malformed-input errors. </p>
354 * <p> This method invokes the {@link #implOnMalformedInput
355 * implOnMalformedInput} method, passing the new action. </p>
357 * @param newAction The new action; must not be <tt>null</tt>
359 * @return This decoder
361 * @throws IllegalArgumentException
362 * If the precondition on the parameter does not hold
364 // public final CharsetDecoder onMalformedInput(CodingErrorAction newAction) {
365 // if (newAction == null)
366 // throw new IllegalArgumentException("Null action");
367 // malformedInputAction = newAction;
368 // implOnMalformedInput(newAction);
373 * Reports a change to this decoder's malformed-input action.
375 * <p> The default implementation of this method does nothing. This method
376 * should be overridden by decoders that require notification of changes to
377 * the malformed-input action. </p>
379 // protected void implOnMalformedInput(CodingErrorAction newAction) { }
382 * Returns this decoder's current action for unmappable-character errors.
385 * @return The current unmappable-character action, which is never
388 // public CodingErrorAction unmappableCharacterAction() {
389 // return unmappableCharacterAction;
393 * Changes this decoder's action for unmappable-character errors.
395 * <p> This method invokes the {@link #implOnUnmappableCharacter
396 * implOnUnmappableCharacter} method, passing the new action. </p>
398 * @param newAction The new action; must not be <tt>null</tt>
400 * @return This decoder
402 * @throws IllegalArgumentException
403 * If the precondition on the parameter does not hold
405 // public final CharsetDecoder onUnmappableCharacter(CodingErrorAction
408 // if (newAction == null)
409 // throw new IllegalArgumentException("Null action");
410 // unmappableCharacterAction = newAction;
411 // implOnUnmappableCharacter(newAction);
416 * Reports a change to this decoder's unmappable-character action.
418 * <p> The default implementation of this method does nothing. This method
419 * should be overridden by decoders that require notification of changes to
420 * the unmappable-character action. </p>
422 // protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
425 * Returns the average number of characters that will be produced for each
426 * byte of input. This heuristic value may be used to estimate the size
427 * of the output buffer required for a given input sequence. </p>
429 * @return The average number of characters produced
432 public final float averageCharsPerByte() {
433 return averageCharsPerByte;
437 * Returns the maximum number of characters that will be produced for each
438 * byte of input. This value may be used to compute the worst-case size
439 * of the output buffer required for a given input sequence. </p>
441 * @return The maximum number of characters that will be produced per
444 public final float maxCharsPerByte() {
445 return maxCharsPerByte;
449 * Decodes as many bytes as possible from the given input buffer,
450 * writing the results to the given output buffer.
452 * <p> The buffers are read from, and written to, starting at their current
453 * positions. At most {@link Buffer#remaining in.remaining()} bytes
454 * will be read and at most {@link Buffer#remaining out.remaining()}
455 * characters will be written. The buffers' positions will be advanced to
456 * reflect the bytes read and the characters written, but their marks and
457 * limits will not be modified.
459 * <p> In addition to reading bytes from the input buffer and writing
460 * characters to the output buffer, this method returns a {@link CoderResult}
461 * object to describe its reason for termination:
465 * <li><p> {@link CoderResult#UNDERFLOW} indicates that as much of the
466 * input buffer as possible has been decoded. If there is no further
467 * input then the invoker can proceed to the next step of the
468 * <a href="#steps">decoding operation</a>. Otherwise this method
469 * should be invoked again with further input. </p></li>
471 * <li><p> {@link CoderResult#OVERFLOW} indicates that there is
472 * insufficient space in the output buffer to decode any more bytes.
473 * This method should be invoked again with an output buffer that has
474 * more {@linkplain Buffer#remaining remaining} characters. This is
475 * typically done by draining any decoded characters from the output
478 * <li><p> A {@link CoderResult#malformedForLength
479 * </code>malformed-input<code>} result indicates that a malformed-input
480 * error has been detected. The malformed bytes begin at the input
481 * buffer's (possibly incremented) position; the number of malformed
482 * bytes may be determined by invoking the result object's {@link
483 * CoderResult#length() length} method. This case applies only if the
484 * {@link #onMalformedInput </code>malformed action<code>} of this decoder
485 * is {@link CodingErrorAction#REPORT}; otherwise the malformed input
486 * will be ignored or replaced, as requested. </p></li>
488 * <li><p> An {@link CoderResult#unmappableForLength
489 * </code>unmappable-character<code>} result indicates that an
490 * unmappable-character error has been detected. The bytes that
491 * decode the unmappable character begin at the input buffer's (possibly
492 * incremented) position; the number of such bytes may be determined
493 * by invoking the result object's {@link CoderResult#length() length}
494 * method. This case applies only if the {@link #onUnmappableCharacter
495 * </code>unmappable action<code>} of this decoder is {@link
496 * CodingErrorAction#REPORT}; otherwise the unmappable character will be
497 * ignored or replaced, as requested. </p></li>
501 * In any case, if this method is to be reinvoked in the same decoding
502 * operation then care should be taken to preserve any bytes remaining
503 * in the input buffer so that they are available to the next invocation.
505 * <p> The <tt>endOfInput</tt> parameter advises this method as to whether
506 * the invoker can provide further input beyond that contained in the given
507 * input buffer. If there is a possibility of providing additional input
508 * then the invoker should pass <tt>false</tt> for this parameter; if there
509 * is no possibility of providing further input then the invoker should
510 * pass <tt>true</tt>. It is not erroneous, and in fact it is quite
511 * common, to pass <tt>false</tt> in one invocation and later discover that
512 * no further input was actually available. It is critical, however, that
513 * the final invocation of this method in a sequence of invocations always
514 * pass <tt>true</tt> so that any remaining undecoded input will be treated
515 * as being malformed.
517 * <p> This method works by invoking the {@link #decodeLoop decodeLoop}
518 * method, interpreting its results, handling error conditions, and
519 * reinvoking it as necessary. </p>
523 * The input byte buffer
526 * The output character buffer
529 * <tt>true</tt> if, and only if, the invoker can provide no
530 * additional input bytes beyond those in the given buffer
532 * @return A coder-result object describing the reason for termination
534 * @throws IllegalStateException
535 * If a decoding operation is already in progress and the previous
536 * step was an invocation neither of the {@link #reset reset}
537 * method, nor of this method with a value of <tt>false</tt> for
538 * the <tt>endOfInput</tt> parameter, nor of this method with a
539 * value of <tt>true</tt> for the <tt>endOfInput</tt> parameter
540 * but a return value indicating an incomplete decoding operation
542 * @throws CoderMalfunctionError
543 * If an invocation of the decodeLoop method threw
544 * an unexpected exception
546 // public final CoderResult decode(ByteBuffer in, CharBuffer out,
547 // boolean endOfInput)
549 // int newState = endOfInput ? ST_END : ST_CODING;
550 // if ((state != ST_RESET) && (state != ST_CODING)
551 // && !(endOfInput && (state == ST_END)))
552 // throwIllegalStateException(state, newState);
559 // cr = decodeLoop(in, out);
560 // } catch (BufferUnderflowException x) {
561 // throw new CoderMalfunctionError(x);
562 // } catch (BufferOverflowException x) {
563 // throw new CoderMalfunctionError(x);
566 // if (cr.isOverflow())
569 // if (cr.isUnderflow()) {
570 // if (endOfInput && in.hasRemaining()) {
571 // cr = CoderResult.malformedForLength(in.remaining());
572 // // Fall through to malformed-input case
578 // CodingErrorAction action = null;
579 // if (cr.isMalformed())
580 // action = malformedInputAction;
581 // else if (cr.isUnmappable())
582 // action = unmappableCharacterAction;
584 // assert false : cr.toString();
586 // if (action == CodingErrorAction.REPORT)
589 // if (action == CodingErrorAction.REPLACE) {
590 // if (out.remaining() < replacement.length())
591 // return CoderResult.OVERFLOW;
592 // out.put(replacement);
595 // if ((action == CodingErrorAction.IGNORE)
596 // || (action == CodingErrorAction.REPLACE)) {
597 // // Skip erroneous input either way
598 // in.position(in.position() + cr.length());
608 * Flushes this decoder.
610 * <p> Some decoders maintain internal state and may need to write some
611 * final characters to the output buffer once the overall input sequence has
614 * <p> Any additional output is written to the output buffer beginning at
615 * its current position. At most {@link Buffer#remaining out.remaining()}
616 * characters will be written. The buffer's position will be advanced
617 * appropriately, but its mark and limit will not be modified.
619 * <p> If this method completes successfully then it returns {@link
620 * CoderResult#UNDERFLOW}. If there is insufficient room in the output
621 * buffer then it returns {@link CoderResult#OVERFLOW}. If this happens
622 * then this method must be invoked again, with an output buffer that has
623 * more room, in order to complete the current <a href="#steps">decoding
626 * <p> If this decoder has already been flushed then invoking this method
629 * <p> This method invokes the {@link #implFlush implFlush} method to
630 * perform the actual flushing operation. </p>
633 * The output character buffer
635 * @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
636 * {@link CoderResult#OVERFLOW}
638 * @throws IllegalStateException
639 * If the previous step of the current decoding operation was an
640 * invocation neither of the {@link #flush flush} method nor of
641 * the three-argument {@link
642 * #decode(ByteBuffer,CharBuffer,boolean) decode} method
643 * with a value of <tt>true</tt> for the <tt>endOfInput</tt>
646 // public final CoderResult flush(CharBuffer out) {
647 // if (state == ST_END) {
648 // CoderResult cr = implFlush(out);
649 // if (cr.isUnderflow())
650 // state = ST_FLUSHED;
654 // if (state != ST_FLUSHED)
655 // throwIllegalStateException(state, ST_FLUSHED);
657 // return CoderResult.UNDERFLOW; // Already flushed
661 * Flushes this decoder.
663 * <p> The default implementation of this method does nothing, and always
664 * returns {@link CoderResult#UNDERFLOW}. This method should be overridden
665 * by decoders that may need to write final characters to the output buffer
666 * once the entire input sequence has been read. </p>
669 * The output character buffer
671 * @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
672 * {@link CoderResult#OVERFLOW}
674 // protected CoderResult implFlush(CharBuffer out) {
675 // return CoderResult.UNDERFLOW;
679 * Resets this decoder, clearing any internal state.
681 * <p> This method resets charset-independent state and also invokes the
682 * {@link #implReset() implReset} method in order to perform any
683 * charset-specific reset actions. </p>
685 * @return This decoder
688 public final CharsetDecoder reset() {
695 * Resets this decoder, clearing any charset-specific internal state.
697 * <p> The default implementation of this method does nothing. This method
698 * should be overridden by decoders that maintain internal state. </p>
700 protected void implReset() { }
703 * Decodes one or more bytes into one or more characters.
705 * <p> This method encapsulates the basic decoding loop, decoding as many
706 * bytes as possible until it either runs out of input, runs out of room
707 * in the output buffer, or encounters a decoding error. This method is
708 * invoked by the {@link #decode decode} method, which handles result
709 * interpretation and error recovery.
711 * <p> The buffers are read from, and written to, starting at their current
712 * positions. At most {@link Buffer#remaining in.remaining()} bytes
713 * will be read, and at most {@link Buffer#remaining out.remaining()}
714 * characters will be written. The buffers' positions will be advanced to
715 * reflect the bytes read and the characters written, but their marks and
716 * limits will not be modified.
718 * <p> This method returns a {@link CoderResult} object to describe its
719 * reason for termination, in the same manner as the {@link #decode decode}
720 * method. Most implementations of this method will handle decoding errors
721 * by returning an appropriate result object for interpretation by the
722 * {@link #decode decode} method. An optimized implementation may instead
723 * examine the relevant error action and implement that action itself.
725 * <p> An implementation of this method may perform arbitrary lookahead by
726 * returning {@link CoderResult#UNDERFLOW} until it receives sufficient
730 * The input byte buffer
733 * The output character buffer
735 * @return A coder-result object describing the reason for termination
737 // protected abstract CoderResult decodeLoop(ByteBuffer in,
741 * Convenience method that decodes the remaining content of a single input
742 * byte buffer into a newly-allocated character buffer.
744 * <p> This method implements an entire <a href="#steps">decoding
745 * operation</a>; that is, it resets this decoder, then it decodes the
746 * bytes in the given byte buffer, and finally it flushes this
747 * decoder. This method should therefore not be invoked if a decoding
748 * operation is already in progress. </p>
751 * The input byte buffer
753 * @return A newly-allocated character buffer containing the result of the
754 * decoding operation. The buffer's position will be zero and its
755 * limit will follow the last character written.
757 * @throws IllegalStateException
758 * If a decoding operation is already in progress
760 * @throws MalformedInputException
761 * If the byte sequence starting at the input buffer's current
762 * position is not legal for this charset and the current malformed-input action
763 * is {@link CodingErrorAction#REPORT}
765 * @throws UnmappableCharacterException
766 * If the byte sequence starting at the input buffer's current
767 * position cannot be mapped to an equivalent character sequence and
768 * the current unmappable-character action is {@link
769 * CodingErrorAction#REPORT}
771 // public final CharBuffer decode(ByteBuffer in)
772 // throws CharacterCodingException
774 // int n = (int)(in.remaining() * averageCharsPerByte());
775 // CharBuffer out = CharBuffer.allocate(n);
777 // if ((n == 0) && (in.remaining() == 0))
781 // CoderResult cr = in.hasRemaining() ?
782 // decode(in, out, true) : CoderResult.UNDERFLOW;
783 // if (cr.isUnderflow())
786 // if (cr.isUnderflow())
788 // if (cr.isOverflow()) {
789 // n = 2*n + 1; // Ensure progress; n might be 0!
790 // CharBuffer o = CharBuffer.allocate(n);
796 // cr.throwException();
805 * Tells whether or not this decoder implements an auto-detecting charset.
807 * <p> The default implementation of this method always returns
808 * <tt>false</tt>; it should be overridden by auto-detecting decoders to
809 * return <tt>true</tt>. </p>
811 * @return <tt>true</tt> if, and only if, this decoder implements an
812 * auto-detecting charset
814 public boolean isAutoDetecting() {
819 * Tells whether or not this decoder has yet detected a
820 * charset <i>(optional operation)</i>.
822 * <p> If this decoder implements an auto-detecting charset then at a
823 * single point during a decoding operation this method may start returning
824 * <tt>true</tt> to indicate that a specific charset has been detected in
825 * the input byte sequence. Once this occurs, the {@link #detectedCharset
826 * detectedCharset} method may be invoked to retrieve the detected charset.
828 * <p> That this method returns <tt>false</tt> does not imply that no bytes
829 * have yet been decoded. Some auto-detecting decoders are capable of
830 * decoding some, or even all, of an input byte sequence without fixing on
831 * a particular charset.
833 * <p> The default implementation of this method always throws an {@link
834 * UnsupportedOperationException}; it should be overridden by
835 * auto-detecting decoders to return <tt>true</tt> once the input charset
836 * has been determined. </p>
838 * @return <tt>true</tt> if, and only if, this decoder has detected a
841 * @throws UnsupportedOperationException
842 * If this decoder does not implement an auto-detecting charset
844 public boolean isCharsetDetected() {
845 throw new UnsupportedOperationException();
849 * Retrieves the charset that was detected by this
850 * decoder <i>(optional operation)</i>.
852 * <p> If this decoder implements an auto-detecting charset then this
853 * method returns the actual charset once it has been detected. After that
854 * point, this method returns the same value for the duration of the
855 * current decoding operation. If not enough input bytes have yet been
856 * read to determine the actual charset then this method throws an {@link
857 * IllegalStateException}.
859 * <p> The default implementation of this method always throws an {@link
860 * UnsupportedOperationException}; it should be overridden by
861 * auto-detecting decoders to return the appropriate value. </p>
863 * @return The charset detected by this auto-detecting decoder,
864 * or <tt>null</tt> if the charset has not yet been determined
866 * @throws IllegalStateException
867 * If insufficient bytes have been read to determine a charset
869 * @throws UnsupportedOperationException
870 * If this decoder does not implement an auto-detecting charset
872 public Charset detectedCharset() {
873 throw new UnsupportedOperationException();
965 private void throwIllegalStateException(int from, int to) {
966 throw new IllegalStateException("Current state = " + stateNames[from]
967 + ", new state = " + stateNames[to]);