rt/emul/compact/src/main/java/java/nio/charset/CharsetDecoder.java
changeset 1343 802e5d2da9f6
parent 1337 c794024954b5
     1.1 --- a/rt/emul/compact/src/main/java/java/nio/charset/CharsetDecoder.java	Thu Oct 03 17:36:44 2013 +0200
     1.2 +++ b/rt/emul/compact/src/main/java/java/nio/charset/CharsetDecoder.java	Fri Oct 04 15:02:17 2013 +0200
     1.3 @@ -27,13 +27,13 @@
     1.4  
     1.5  package java.nio.charset;
     1.6  
     1.7 -import java.nio.Buffer;
     1.8 -import java.nio.ByteBuffer;
     1.9 -import java.nio.CharBuffer;
    1.10 -import java.nio.BufferOverflowException;
    1.11 -import java.nio.BufferUnderflowException;
    1.12 +//import java.nio.Buffer;
    1.13 +//import java.nio.ByteBuffer;
    1.14 +//import java.nio.CharBuffer;
    1.15 +//import java.nio.BufferOverflowException;
    1.16 +//import java.nio.BufferUnderflowException;
    1.17  import java.lang.ref.WeakReference;
    1.18 -import java.nio.charset.CoderMalfunctionError;                  // javadoc
    1.19 +//import java.nio.charset.CoderMalfunctionError;                  // javadoc
    1.20  
    1.21  
    1.22  /**
    1.23 @@ -140,10 +140,10 @@
    1.24      private final float maxCharsPerByte;
    1.25  
    1.26      private String replacement;
    1.27 -    private CodingErrorAction malformedInputAction
    1.28 -        = CodingErrorAction.REPORT;
    1.29 -    private CodingErrorAction unmappableCharacterAction
    1.30 -        = CodingErrorAction.REPORT;
    1.31 +//    private CodingErrorAction malformedInputAction
    1.32 +//        = CodingErrorAction.REPORT;
    1.33 +//    private CodingErrorAction unmappableCharacterAction
    1.34 +//        = CodingErrorAction.REPORT;
    1.35  
    1.36      // Internal states
    1.37      //
    1.38 @@ -191,12 +191,10 @@
    1.39          if (maxCharsPerByte <= 0.0f)
    1.40              throw new IllegalArgumentException("Non-positive "
    1.41                                                 + "maxCharsPerByte");
    1.42 -        if (!Charset.atBugLevel("1.4")) {
    1.43 -            if (averageCharsPerByte > maxCharsPerByte)
    1.44 -                throw new IllegalArgumentException("averageCharsPerByte"
    1.45 -                                                   + " exceeds "
    1.46 -                                                   + "maxCharsPerByte");
    1.47 -        }
    1.48 +        if (averageCharsPerByte > maxCharsPerByte)
    1.49 +            throw new IllegalArgumentException("averageCharsPerByte"
    1.50 +                                               + " exceeds "
    1.51 +                                               + "maxCharsPerByte");
    1.52          this.replacement = replacement;
    1.53          this.averageCharsPerByte = averageCharsPerByte;
    1.54          this.maxCharsPerByte = maxCharsPerByte;
    1.55 @@ -346,9 +344,9 @@
    1.56       *
    1.57       * @return The current malformed-input action, which is never <tt>null</tt>
    1.58       */
    1.59 -    public CodingErrorAction malformedInputAction() {
    1.60 -        return malformedInputAction;
    1.61 -    }
    1.62 +//    public CodingErrorAction malformedInputAction() {
    1.63 +//        return malformedInputAction;
    1.64 +//    }
    1.65  
    1.66      /**
    1.67       * Changes this decoder's action for malformed-input errors.  </p>
    1.68 @@ -363,13 +361,13 @@
    1.69       * @throws IllegalArgumentException
    1.70       *         If the precondition on the parameter does not hold
    1.71       */
    1.72 -    public final CharsetDecoder onMalformedInput(CodingErrorAction newAction) {
    1.73 -        if (newAction == null)
    1.74 -            throw new IllegalArgumentException("Null action");
    1.75 -        malformedInputAction = newAction;
    1.76 -        implOnMalformedInput(newAction);
    1.77 -        return this;
    1.78 -    }
    1.79 +//    public final CharsetDecoder onMalformedInput(CodingErrorAction newAction) {
    1.80 +//        if (newAction == null)
    1.81 +//            throw new IllegalArgumentException("Null action");
    1.82 +//        malformedInputAction = newAction;
    1.83 +//        implOnMalformedInput(newAction);
    1.84 +//        return this;
    1.85 +//    }
    1.86  
    1.87      /**
    1.88       * Reports a change to this decoder's malformed-input action.
    1.89 @@ -378,7 +376,7 @@
    1.90       * should be overridden by decoders that require notification of changes to
    1.91       * the malformed-input action.  </p>
    1.92       */
    1.93 -    protected void implOnMalformedInput(CodingErrorAction newAction) { }
    1.94 +//    protected void implOnMalformedInput(CodingErrorAction newAction) { }
    1.95  
    1.96      /**
    1.97       * Returns this decoder's current action for unmappable-character errors.
    1.98 @@ -387,9 +385,9 @@
    1.99       * @return The current unmappable-character action, which is never
   1.100       *         <tt>null</tt>
   1.101       */
   1.102 -    public CodingErrorAction unmappableCharacterAction() {
   1.103 -        return unmappableCharacterAction;
   1.104 -    }
   1.105 +//    public CodingErrorAction unmappableCharacterAction() {
   1.106 +//        return unmappableCharacterAction;
   1.107 +//    }
   1.108  
   1.109      /**
   1.110       * Changes this decoder's action for unmappable-character errors.
   1.111 @@ -404,15 +402,15 @@
   1.112       * @throws IllegalArgumentException
   1.113       *         If the precondition on the parameter does not hold
   1.114       */
   1.115 -    public final CharsetDecoder onUnmappableCharacter(CodingErrorAction
   1.116 -                                                      newAction)
   1.117 -    {
   1.118 -        if (newAction == null)
   1.119 -            throw new IllegalArgumentException("Null action");
   1.120 -        unmappableCharacterAction = newAction;
   1.121 -        implOnUnmappableCharacter(newAction);
   1.122 -        return this;
   1.123 -    }
   1.124 +//    public final CharsetDecoder onUnmappableCharacter(CodingErrorAction
   1.125 +//                                                      newAction)
   1.126 +//    {
   1.127 +//        if (newAction == null)
   1.128 +//            throw new IllegalArgumentException("Null action");
   1.129 +//        unmappableCharacterAction = newAction;
   1.130 +//        implOnUnmappableCharacter(newAction);
   1.131 +//        return this;
   1.132 +//    }
   1.133  
   1.134      /**
   1.135       * Reports a change to this decoder's unmappable-character action.
   1.136 @@ -421,7 +419,7 @@
   1.137       * should be overridden by decoders that require notification of changes to
   1.138       * the unmappable-character action.  </p>
   1.139       */
   1.140 -    protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
   1.141 +//    protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
   1.142  
   1.143      /**
   1.144       * Returns the average number of characters that will be produced for each
   1.145 @@ -545,66 +543,66 @@
   1.146       *          If an invocation of the decodeLoop method threw
   1.147       *          an unexpected exception
   1.148       */
   1.149 -    public final CoderResult decode(ByteBuffer in, CharBuffer out,
   1.150 -                                    boolean endOfInput)
   1.151 -    {
   1.152 -        int newState = endOfInput ? ST_END : ST_CODING;
   1.153 -        if ((state != ST_RESET) && (state != ST_CODING)
   1.154 -            && !(endOfInput && (state == ST_END)))
   1.155 -            throwIllegalStateException(state, newState);
   1.156 -        state = newState;
   1.157 -
   1.158 -        for (;;) {
   1.159 -
   1.160 -            CoderResult cr;
   1.161 -            try {
   1.162 -                cr = decodeLoop(in, out);
   1.163 -            } catch (BufferUnderflowException x) {
   1.164 -                throw new CoderMalfunctionError(x);
   1.165 -            } catch (BufferOverflowException x) {
   1.166 -                throw new CoderMalfunctionError(x);
   1.167 -            }
   1.168 -
   1.169 -            if (cr.isOverflow())
   1.170 -                return cr;
   1.171 -
   1.172 -            if (cr.isUnderflow()) {
   1.173 -                if (endOfInput && in.hasRemaining()) {
   1.174 -                    cr = CoderResult.malformedForLength(in.remaining());
   1.175 -                    // Fall through to malformed-input case
   1.176 -                } else {
   1.177 -                    return cr;
   1.178 -                }
   1.179 -            }
   1.180 -
   1.181 -            CodingErrorAction action = null;
   1.182 -            if (cr.isMalformed())
   1.183 -                action = malformedInputAction;
   1.184 -            else if (cr.isUnmappable())
   1.185 -                action = unmappableCharacterAction;
   1.186 -            else
   1.187 -                assert false : cr.toString();
   1.188 -
   1.189 -            if (action == CodingErrorAction.REPORT)
   1.190 -                return cr;
   1.191 -
   1.192 -            if (action == CodingErrorAction.REPLACE) {
   1.193 -                if (out.remaining() < replacement.length())
   1.194 -                    return CoderResult.OVERFLOW;
   1.195 -                out.put(replacement);
   1.196 -            }
   1.197 -
   1.198 -            if ((action == CodingErrorAction.IGNORE)
   1.199 -                || (action == CodingErrorAction.REPLACE)) {
   1.200 -                // Skip erroneous input either way
   1.201 -                in.position(in.position() + cr.length());
   1.202 -                continue;
   1.203 -            }
   1.204 -
   1.205 -            assert false;
   1.206 -        }
   1.207 -
   1.208 -    }
   1.209 +//    public final CoderResult decode(ByteBuffer in, CharBuffer out,
   1.210 +//                                    boolean endOfInput)
   1.211 +//    {
   1.212 +//        int newState = endOfInput ? ST_END : ST_CODING;
   1.213 +//        if ((state != ST_RESET) && (state != ST_CODING)
   1.214 +//            && !(endOfInput && (state == ST_END)))
   1.215 +//            throwIllegalStateException(state, newState);
   1.216 +//        state = newState;
   1.217 +//
   1.218 +//        for (;;) {
   1.219 +//
   1.220 +//            CoderResult cr;
   1.221 +//            try {
   1.222 +//                cr = decodeLoop(in, out);
   1.223 +//            } catch (BufferUnderflowException x) {
   1.224 +//                throw new CoderMalfunctionError(x);
   1.225 +//            } catch (BufferOverflowException x) {
   1.226 +//                throw new CoderMalfunctionError(x);
   1.227 +//            }
   1.228 +//
   1.229 +//            if (cr.isOverflow())
   1.230 +//                return cr;
   1.231 +//
   1.232 +//            if (cr.isUnderflow()) {
   1.233 +//                if (endOfInput && in.hasRemaining()) {
   1.234 +//                    cr = CoderResult.malformedForLength(in.remaining());
   1.235 +//                    // Fall through to malformed-input case
   1.236 +//                } else {
   1.237 +//                    return cr;
   1.238 +//                }
   1.239 +//            }
   1.240 +//
   1.241 +//            CodingErrorAction action = null;
   1.242 +//            if (cr.isMalformed())
   1.243 +//                action = malformedInputAction;
   1.244 +//            else if (cr.isUnmappable())
   1.245 +//                action = unmappableCharacterAction;
   1.246 +//            else
   1.247 +//                assert false : cr.toString();
   1.248 +//
   1.249 +//            if (action == CodingErrorAction.REPORT)
   1.250 +//                return cr;
   1.251 +//
   1.252 +//            if (action == CodingErrorAction.REPLACE) {
   1.253 +//                if (out.remaining() < replacement.length())
   1.254 +//                    return CoderResult.OVERFLOW;
   1.255 +//                out.put(replacement);
   1.256 +//            }
   1.257 +//
   1.258 +//            if ((action == CodingErrorAction.IGNORE)
   1.259 +//                || (action == CodingErrorAction.REPLACE)) {
   1.260 +//                // Skip erroneous input either way
   1.261 +//                in.position(in.position() + cr.length());
   1.262 +//                continue;
   1.263 +//            }
   1.264 +//
   1.265 +//            assert false;
   1.266 +//        }
   1.267 +//
   1.268 +//    }
   1.269  
   1.270      /**
   1.271       * Flushes this decoder.
   1.272 @@ -645,19 +643,19 @@
   1.273       *          with a value of <tt>true</tt> for the <tt>endOfInput</tt>
   1.274       *          parameter
   1.275       */
   1.276 -    public final CoderResult flush(CharBuffer out) {
   1.277 -        if (state == ST_END) {
   1.278 -            CoderResult cr = implFlush(out);
   1.279 -            if (cr.isUnderflow())
   1.280 -                state = ST_FLUSHED;
   1.281 -            return cr;
   1.282 -        }
   1.283 -
   1.284 -        if (state != ST_FLUSHED)
   1.285 -            throwIllegalStateException(state, ST_FLUSHED);
   1.286 -
   1.287 -        return CoderResult.UNDERFLOW; // Already flushed
   1.288 -    }
   1.289 +//    public final CoderResult flush(CharBuffer out) {
   1.290 +//        if (state == ST_END) {
   1.291 +//            CoderResult cr = implFlush(out);
   1.292 +//            if (cr.isUnderflow())
   1.293 +//                state = ST_FLUSHED;
   1.294 +//            return cr;
   1.295 +//        }
   1.296 +//
   1.297 +//        if (state != ST_FLUSHED)
   1.298 +//            throwIllegalStateException(state, ST_FLUSHED);
   1.299 +//
   1.300 +//        return CoderResult.UNDERFLOW; // Already flushed
   1.301 +//    }
   1.302  
   1.303      /**
   1.304       * Flushes this decoder.
   1.305 @@ -673,9 +671,9 @@
   1.306       * @return  A coder-result object, either {@link CoderResult#UNDERFLOW} or
   1.307       *          {@link CoderResult#OVERFLOW}
   1.308       */
   1.309 -    protected CoderResult implFlush(CharBuffer out) {
   1.310 -        return CoderResult.UNDERFLOW;
   1.311 -    }
   1.312 +//    protected CoderResult implFlush(CharBuffer out) {
   1.313 +//        return CoderResult.UNDERFLOW;
   1.314 +//    }
   1.315  
   1.316      /**
   1.317       * Resets this decoder, clearing any internal state.
   1.318 @@ -736,8 +734,8 @@
   1.319       *
   1.320       * @return  A coder-result object describing the reason for termination
   1.321       */
   1.322 -    protected abstract CoderResult decodeLoop(ByteBuffer in,
   1.323 -                                              CharBuffer out);
   1.324 +//    protected abstract CoderResult decodeLoop(ByteBuffer in,
   1.325 +//                                              CharBuffer out);
   1.326  
   1.327      /**
   1.328       * Convenience method that decodes the remaining content of a single input
   1.329 @@ -770,36 +768,36 @@
   1.330       *          the current unmappable-character action is {@link
   1.331       *          CodingErrorAction#REPORT}
   1.332       */
   1.333 -    public final CharBuffer decode(ByteBuffer in)
   1.334 -        throws CharacterCodingException
   1.335 -    {
   1.336 -        int n = (int)(in.remaining() * averageCharsPerByte());
   1.337 -        CharBuffer out = CharBuffer.allocate(n);
   1.338 -
   1.339 -        if ((n == 0) && (in.remaining() == 0))
   1.340 -            return out;
   1.341 -        reset();
   1.342 -        for (;;) {
   1.343 -            CoderResult cr = in.hasRemaining() ?
   1.344 -                decode(in, out, true) : CoderResult.UNDERFLOW;
   1.345 -            if (cr.isUnderflow())
   1.346 -                cr = flush(out);
   1.347 -
   1.348 -            if (cr.isUnderflow())
   1.349 -                break;
   1.350 -            if (cr.isOverflow()) {
   1.351 -                n = 2*n + 1;    // Ensure progress; n might be 0!
   1.352 -                CharBuffer o = CharBuffer.allocate(n);
   1.353 -                out.flip();
   1.354 -                o.put(out);
   1.355 -                out = o;
   1.356 -                continue;
   1.357 -            }
   1.358 -            cr.throwException();
   1.359 -        }
   1.360 -        out.flip();
   1.361 -        return out;
   1.362 -    }
   1.363 +//    public final CharBuffer decode(ByteBuffer in)
   1.364 +//        throws CharacterCodingException
   1.365 +//    {
   1.366 +//        int n = (int)(in.remaining() * averageCharsPerByte());
   1.367 +//        CharBuffer out = CharBuffer.allocate(n);
   1.368 +//
   1.369 +//        if ((n == 0) && (in.remaining() == 0))
   1.370 +//            return out;
   1.371 +//        reset();
   1.372 +//        for (;;) {
   1.373 +//            CoderResult cr = in.hasRemaining() ?
   1.374 +//                decode(in, out, true) : CoderResult.UNDERFLOW;
   1.375 +//            if (cr.isUnderflow())
   1.376 +//                cr = flush(out);
   1.377 +//
   1.378 +//            if (cr.isUnderflow())
   1.379 +//                break;
   1.380 +//            if (cr.isOverflow()) {
   1.381 +//                n = 2*n + 1;    // Ensure progress; n might be 0!
   1.382 +//                CharBuffer o = CharBuffer.allocate(n);
   1.383 +//                out.flip();
   1.384 +//                o.put(out);
   1.385 +//                out = o;
   1.386 +//                continue;
   1.387 +//            }
   1.388 +//            cr.throwException();
   1.389 +//        }
   1.390 +//        out.flip();
   1.391 +//        return out;
   1.392 +//    }
   1.393  
   1.394  
   1.395