Examples of maxBytesPerChar()


Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

        currentFilePart = new FilePart(totalBlockCount, lastBlockLength, null);

        // --- check & prepare encoding ---
        Charset charset = Charset.forName(encoding);
        CharsetEncoder charsetEncoder = charset.newEncoder();
        float maxBytesPerChar = charsetEncoder.maxBytesPerChar();
        if(maxBytesPerChar==1f) {
            // all one byte encodings are no problem
            byteDecrement = 1;
        } else if(charset == Charset.forName("UTF-8")) {
            // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

    // normal case
    CharsetEncoder ec = new MockCharsetEncoder(cs, 1, MAX_BYTES);
    assertSame(ec.charset(), cs);
    assertEquals(1.0, ec.averageBytesPerChar(), 0);
    assertTrue(ec.maxBytesPerChar() == MAX_BYTES);

    /*
     * ------------------------ Exceptional cases -------------------------
     */
    // NullPointerException: null charset
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

    byte[] ba = getLegalByteArray();
    // normal case
    CharsetEncoder ec = new MockCharsetEncoder(cs, 1, MAX_BYTES, ba);
    assertSame(ec.charset(), cs);
    assertEquals(1.0, ec.averageBytesPerChar(), 0.0);
    assertTrue(ec.maxBytesPerChar() == MAX_BYTES);
    assertSame(ba, ec.replacement());

    /*
     * ------------------------ Exceptional cases -------------------------
     */
 
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

        return encodeString0(alloc, false, src, charset);
    }

    static ByteBuf encodeString0(ByteBufAllocator alloc, boolean enforceHeap, CharBuffer src, Charset charset) {
        final CharsetEncoder encoder = CharsetUtil.getEncoder(charset);
        int length = (int) ((double) src.remaining() * encoder.maxBytesPerChar());
        boolean release = true;
        final ByteBuf dst;
        if (enforceHeap) {
            dst = alloc.heapBuffer(length);
        } else {
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

            w.writeInt(1);
            w.writeLong(rec.timestamp.toUtcNanos());
            w.writeInt(machineBytes.length);
            w.write(machineBytes);

            int maxLen = Math.round(rec.message.length() * enc.maxBytesPerChar() + 1);
            if(maxLen > maxMsg.limit()) {
                maxMsg = ByteBuffer.allocate(maxLen);
            }
            enc.reset();
            enc.encode(CharBuffer.wrap(rec.message), maxMsg, true);
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

        int n = 0;
        if (buffer.remaining() > 0) {
            n = (int) (buffer.remaining() * encoder.averageBytesPerChar());
            if (n == 0)
                n = (int) (buffer.remaining() * encoder.maxBytesPerChar());
        }
        ByteBuffer result = ByteBuffer.allocate(n);
        if (n == 0)
            return result;

View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

        currentFilePart = new FilePart(totalBlockCount, lastBlockLength, null);

        // --- check & prepare encoding ---
        final Charset charset = Charsets.toCharset(encoding);
        final CharsetEncoder charsetEncoder = charset.newEncoder();
        final float maxBytesPerChar = charsetEncoder.maxBytesPerChar();
        if (maxBytesPerChar == 1f) {
            // all one byte encodings are no problem
            byteDecrement = 1;
        } else if (charset == Charsets.UTF_8) {
            // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

        CharsetEncoder enc = cs.newEncoder();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        for (int i = 0; i < encoded.length(); i++) {
            CharBuffer in = CharBuffer.allocate(1);
            in.put(encoded.charAt(i)).flip();
            ByteBuffer bout = ByteBuffer.allocate((int)enc.maxBytesPerChar());
            enc.encode(in, bout, (i == (encoded.length() - 1)));
            if (bout.flip().hasRemaining()) {
                byte[] ob = new byte[bout.remaining()];
                bout.get(ob);
                bos.write(ob);
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

                bout.get(ob);
                bos.write(ob);
            }
        }

        ByteBuffer bout = ByteBuffer.allocate((int)enc.maxBytesPerChar());
        enc.flush(bout);
        if (bout.flip().hasRemaining()) {
            byte[] ob = new byte[bout.remaining()];
            bout.get(ob);
            bos.write(ob);
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.maxBytesPerChar()

    }

    static ByteBuffer encodeString(CharBuffer src, Charset charset) {
        final CharsetEncoder encoder = CharsetUtil.getEncoder(charset);
        final ByteBuffer dst = ByteBuffer.allocate(
                (int) ((double) src.remaining() * encoder.maxBytesPerChar()));
        try {
            CoderResult cr = encoder.encode(src, dst, true);
            if (!cr.isUnderflow()) {
                cr.throwException();
            }
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.