Examples of averageCharsPerByte()


Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

         * ------------------------ Exceptional cases -------------------------
         */
        // Normal case: null charset
        ec = new MockCharsetDecoder(null, 1, MAX_BYTES);
        assertNull(ec.charset());
        assertEquals(1.0, ec.averageCharsPerByte(), 0.0);
        assertTrue(ec.maxCharsPerByte() == MAX_BYTES);

        ec = new MockCharsetDecoder(new CharsetEncoderTest.MockCharset("mock",
                new String[0]), 1, MAX_BYTES);

View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

            processingChars = true;
            final String enc = httpHeader.getCharacterEncoding();
            if (enc != null) {
                encoding = enc;
                final CharsetDecoder localDecoder = getDecoder();
                averageCharsPerByte = localDecoder.averageCharsPerByte();
            }
        }

    }
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

    public CharBuffer decode(ByteBuffer buffer) {
        CharsetDecoder decoder = getDecoder();

        int n = 0;
        if (buffer.remaining() > 0) {
            n = (int) (buffer.remaining() * decoder.averageCharsPerByte());
            if (n == 0)
                n = (int) (buffer.remaining() * decoder.maxCharsPerByte());
        }
        CharBuffer result = CharBuffer.allocate(n);
        if (n == 0)
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

     * Using a CharsetDecoder, translate the ByteBuffer into a stream, updating the buffer's position as we go.
     */
    public static String bufferToString(ByteBuffer buf, Charset cs)
    {
        CharsetDecoder decoder = Charsets.get().getDecoder(cs);
        int bufLen = (int)(buf.limit() * decoder.averageCharsPerByte());
        CharBuffer cBuf = CharBuffer.allocate(bufLen);
        CoderResult result;
        do {
            result = decoder.decode(buf, cBuf, true);
            if (result.isOverflow()) {
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

        CharsetDecoder decoder = Charsets.get().getDecoder(cs);
        int totalBytes = 0;
        for (int i = 0; i < bufs.length; i++) {
            totalBytes += (bufs[i] == null ? 0 : bufs[i].remaining());
        }
        int bufLen = (int)(totalBytes * decoder.averageCharsPerByte());
        CharBuffer cBuf = CharBuffer.allocate(bufLen);
        CoderResult result;
        for (int i = 0; i < bufs.length; i++) {
            do {
                result = decoder.decode(bufs[i], cBuf, (i == (bufs.length - 1)));
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

            return (CharBuffer)CharBuffer.allocate(1).flip();
        }

        // slightly overestimate the buffer size to avoid reallocation.
        float factor =
            decoder.averageCharsPerByte() * 0.8f +
            decoder.maxCharsPerByte() * 0.2f;
        CharBuffer dest = CharBuffer.
            allocate(10 + (int)(inbuf.remaining()*factor));

        while (true) {
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

            return (CharBuffer)CharBuffer.allocate(1).flip();
        }

        // slightly overestimate the buffer size to avoid reallocation.
        float factor =
            decoder.averageCharsPerByte() * 0.8f +
            decoder.maxCharsPerByte() * 0.2f;
        CharBuffer dest = CharBuffer.
            allocate(10 + (int)(inbuf.remaining()*factor));

        while (true) {
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

            processingChars = true;
            final String enc = httpHeader.getCharacterEncoding();
            if (enc != null) {
                encoding = enc;
                final CharsetDecoder localDecoder = getDecoder();
                averageCharsPerByte = localDecoder.averageCharsPerByte();
            }
        }

    }
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

    private String utf8Decode(byte[] data) {
        String reason;
        final ByteBuffer b = ByteBuffer.wrap(data, 2, data.length - 2);
        Charset charset = new StrictUtf8();
        final CharsetDecoder decoder = charset.newDecoder();
        int n = (int) (b.remaining() * decoder.averageCharsPerByte());
        CharBuffer cb = CharBuffer.allocate(n);
        while (true) {
            CoderResult result = decoder.decode(b, cb, true);
            if (result.isUnderflow()) {
                decoder.flush(cb);
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.averageCharsPerByte()

            return (CharBuffer)CharBuffer.allocate(1).flip();
        }

        // slightly overestimate the buffer size to avoid reallocation.
        float factor =
            decoder.averageCharsPerByte() * 0.8f +
            decoder.maxCharsPerByte() * 0.2f;
        CharBuffer dest = CharBuffer.
            allocate(10 + (int)(inbuf.remaining()*factor));

        while (true) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.