Package java.nio.charset

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


            newEncoder.encode(in);
        }
       
        //Encoding -> encode
        {
            newEncoder.reset();
            CharBuffer in = CharBuffer.wrap("A");
            ByteBuffer out = ByteBuffer.allocate(0x10);
            newEncoder.encode(in, out, false);
            in = CharBuffer.wrap("BC");
            newEncoder.encode(in);
View Full Code Here


            newEncoder.encode(in);
        }
       
        //Encoding_end -> encode
        {
            newEncoder.reset();
            CharBuffer in = CharBuffer.wrap("A");
            ByteBuffer out = ByteBuffer.allocate(0x10);
            newEncoder.encode(in, out, true);
            in = CharBuffer.wrap("BC");
            newEncoder.encode(in);
View Full Code Here

            newEncoder.encode(in);
        }
       
        //Flushed -> reset
        {
            newEncoder.reset();
            CharBuffer in = CharBuffer.wrap("A");
            ByteBuffer out = ByteBuffer.allocate(0x10);
            newEncoder.encode(in, out, true);
            in = CharBuffer.wrap("BC");
            newEncoder.flush(out);
View Full Code Here

       
        //Encode -> Reset
        {
            CharBuffer in = CharBuffer.wrap("A");
            newEncoder.encode(in);
            newEncoder.reset();
        }
       
        // Encode -> encoding
        {
            CharBuffer in = CharBuffer.wrap("A");
View Full Code Here

        }

        Map<Charset, CharsetEncoder> map = encoders.get();
        CharsetEncoder e = map.get(charset);
        if (e != null) {
            e.reset();
            e.onMalformedInput(CodingErrorAction.REPLACE);
            e.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return e;
        }
View Full Code Here

            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);
            enc.flush(maxMsg);
            int bytesWritten = maxMsg.position();
            maxMsg.position(0);

View Full Code Here

            int maxLen = rec.message.length() * 2;
            if(maxLen > maxMsg.limit()) {
                maxMsg = ByteBuffer.allocate(maxLen);
            }
            enc.reset();
            enc.encode(CharBuffer.wrap(rec.message), maxMsg, true);
            maxMsg.position(0);

            w.writeInt(maxMsg.limit());
            w.write(maxMsg.array(), maxMsg.arrayOffset(), maxMsg.limit());
View Full Code Here

        if (charset == null) {
            throw new IllegalArgumentException("Charset can not be null");
        }
       
        final CharsetEncoder encoder = obtainCodecsCache().getEncoder(charset);
        encoder.reset();
       
        return encoder;
    }

    private static CodecsCache obtainCodecsCache() {
View Full Code Here

        }
        ByteBuffer result = ByteBuffer.allocate(n);
        if (n == 0)
            return result;

        encoder.reset();
        while (true) {
            CoderResult cr = buffer.hasRemaining() ? encoder.encode(buffer,
                    result, true) : encoder.flush(result);
            if (cr.isUnderflow())
                break;
View Full Code Here

     * @return
     *     the encoded ByteBuffers
     */
    public ByteBuffer[] encode(CharBuffer buffer, int bufferMaxLength) {
        CharsetEncoder encoder = getEncoder();
        encoder.reset();

        Collection buffers = new ArrayList();
        while (true) {
            ByteBuffer out = ByteBuffer.allocate(bufferMaxLength);
            CoderResult cr = encoder.encode(buffer, out, 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.