View | Details | Raw Unified | Return to bug 52579
Collapse All | Expand All

(-)java/org/apache/tomcat/util/buf/ByteChunk.java (-6 / +17 lines)
Lines 23-28 Link Here
23
import java.nio.ByteBuffer;
23
import java.nio.ByteBuffer;
24
import java.nio.CharBuffer;
24
import java.nio.CharBuffer;
25
import java.nio.charset.Charset;
25
import java.nio.charset.Charset;
26
import java.nio.charset.CharsetDecoder;
27
import java.nio.charset.CoderResult;
28
import java.nio.charset.CodingErrorAction;
26
29
27
/*
30
/*
28
 * In a server it is very important to be able to operate on
31
 * In a server it is very important to be able to operate on
Lines 510-521 Link Here
510
        if (charset == null) {
513
        if (charset == null) {
511
            charset = DEFAULT_CHARSET;
514
            charset = DEFAULT_CHARSET;
512
        }
515
        }
513
        // new String(byte[], int, int, Charset) takes a defensive copy of the
516
        CharsetDecoder dec = charset.newDecoder().onMalformedInput(
514
        // entire byte array. This is expensive if only a small subset of the
517
                CodingErrorAction.REPLACE).onUnmappableCharacter(
515
        // bytes will be used. The code below is from Apache Harmony.
518
                CodingErrorAction.REPLACE);
516
        CharBuffer cb;
519
        char[] charAry = new char[(int) ((end - start) * dec.maxCharsPerByte())];
517
        cb = charset.decode(ByteBuffer.wrap(buff, start, end-start));
520
518
        return new String(cb.array(), cb.arrayOffset(), cb.length());
521
        CharBuffer cbuff = CharBuffer.wrap(charAry);
522
        CoderResult result;
523
524
        result = dec.decode(ByteBuffer.wrap(buff, start, end - start), cbuff, true);
525
        if (!result.isUnderflow()) return new String(buff, start, end-start);
526
        result = dec.flush(cbuff);
527
        if (!result.isUnderflow()) return new String(buff, start, end-start);
528
529
        return new String(charAry, 0, cbuff.position());
519
    }
530
    }
520
531
521
    public int getInt()
532
    public int getInt()

Return to bug 52579