Package java.nio.charset

Examples of java.nio.charset.CoderResult


            int expectedLength = (int) ( buf.remaining() * decoder.averageCharsPerByte() ) + 1;
            CharBuffer out = CharBuffer.allocate( expectedLength );
            for( ;; )
            {
                CoderResult cr;
                if ( buf.hasRemaining() )
                {
                    cr = decoder.decode( buf, out, true );
                }
                else
                {
                    cr = decoder.flush( out );
                }
               
                if ( cr.isUnderflow() )
                {
                    break;
                }
               
                if ( cr.isOverflow() )
                {
                    CharBuffer o = CharBuffer.allocate( out.capacity() + expectedLength );
                    out.flip();
                    o.put(out);
                    out = o;
                    continue;
                }

                cr.throwException();
            }
           
            buf.limit( oldLimit );
            buf.position( end );
            return out.flip().toString();
View Full Code Here


            int expectedLength = (int) ( buf.remaining() * decoder.averageCharsPerByte() ) + 1;
            CharBuffer out = CharBuffer.allocate( expectedLength );
            for( ;; )
            {
                CoderResult cr;
                if ( buf.hasRemaining() )
                {
                    cr = decoder.decode( buf, out, true );
                }
                else
                {
                    cr = decoder.flush( out );
                }
               
                if ( cr.isUnderflow() )
                {
                    break;
                }
               
                if ( cr.isOverflow() )
                {
                    CharBuffer o = CharBuffer.allocate( out.capacity() + expectedLength );
                    out.flip();
                    o.put(out);
                    out = o;
                    continue;
                }

                cr.throwException();
            }
           
            buf.limit( oldLimit );
            buf.position( end );
            return out.flip().toString();
View Full Code Here

            CharBuffer in = CharBuffer.wrap( val );
            buf.limit( end );
            encoder.reset();

            for (;;) {
                CoderResult cr;
                if( in.hasRemaining() )
                {
                    cr = encoder.encode( in, buf(), true );
                }
                else
                {
                    cr = encoder.flush( buf() );
                }
               
                if( cr.isUnderflow() || cr.isOverflow() )
                {
                    break;
                }
                cr.throwException();
            }

            buf.limit( oldLimit );

            if( buf.position() < end )
View Full Code Here

            int expectedLength = (int) (in.remaining() * encoder.averageBytesPerChar()) + 1;

            encoder.reset();

            for (;;) {
                CoderResult cr;
                if( in.hasRemaining() )
                {
                    cr = encoder.encode( in, buf(), true );
                }
                else
                {
                    cr = encoder.flush( buf() );
                }
               
                if( cr.isUnderflow() )
                {
                    break;
                }
                if( cr.isOverflow() && autoExpand )
                {
                    autoExpand( expectedLength );
                    continue;
                }
                cr.throwException();
            }
            return this;
        }
View Full Code Here

        decodeAndWriteBuffered(writer, in, out, decoder, endOfInput);
    }

    private static void decodeAndWriteBuffered(Writer writer, ByteBuffer in, CharBuffer out, CharsetDecoder decoder, boolean endOfInput) throws IOException {
        // Decode
        CoderResult result;
        do {
            result = decodeAndWrite(writer, in, out, decoder, endOfInput);
            // Check that all data are decoded
            if (in.hasRemaining()) {
                // Move remaining to top of buffer
                in.compact();
                if (result.isOverflow() && !result.isError() && !result.isMalformed()) {
                    // Not all buffer chars decoded, spin it again
                    // Set to begin
                    in.flip();
                }
            } else {
                // Clean up buffer
                in.clear();
            }
        } while (in.hasRemaining() && result.isOverflow() && !result.isError() && !result.isMalformed());
    }
View Full Code Here

            }
        } while (in.hasRemaining() && result.isOverflow() && !result.isError() && !result.isMalformed());
    }

    private static CoderResult decodeAndWrite(Writer writer, ByteBuffer in, CharBuffer out, CharsetDecoder decoder, boolean endOfInput) throws IOException {
        CoderResult result = decoder.decode(in, out, endOfInput);
        // To begin of decoded data
        out.flip();
        // Output
        writer.write(out.toString());
        return result;
View Full Code Here

            if (bytesRead <= 0) {
                break;
            }
            this.bbuf.flip();
            final boolean completed = decoder.isCompleted();
            CoderResult result = this.chardecoder.decode(this.bbuf, this.cbuf, completed);
            handleDecodingResult(result, ioctrl);
            this.bbuf.compact();
            if (completed) {
                result = this.chardecoder.flush(this.cbuf);
                handleDecodingResult(result, ioctrl);
View Full Code Here

            return;
        }
        bb.flip();
        cd.reset();
        if (bb.hasRemaining()) {
            CoderResult cr = cd.decode(bb, cb, true);
            cd.flush(cb);
            if (cr.isMalformed()) {
                // Move the tail bytes to the head
                int tailLength = bb.remaining();
                if (tailLength >= MALFORMED_INPUT_MAX_LENGTH) {
                    // We only expect the bytes of one character to be broken
                    throw new MalformedInputException(tailLength);
View Full Code Here

        decoder.reset();

        int expectedLength = (int) (remaining() * decoder.averageCharsPerByte()) + 1;
        CharBuffer out = CharBuffer.allocate(expectedLength);
        for (;;) {
            CoderResult cr;
            if (hasRemaining()) {
                cr = decoder.decode(buf(), out, true);
            } else {
                cr = decoder.flush(out);
            }

            if (cr.isUnderflow()) {
                break;
            }

            if (cr.isOverflow()) {
                CharBuffer o = CharBuffer.allocate(out.capacity()
                        + expectedLength);
                out.flip();
                o.put(out);
                out = o;
                continue;
            }

            if (cr.isError()) {
                // Revert the buffer back to the previous state.
                limit(oldLimit);
                position(oldPos);
                cr.throwException();
            }
        }

        limit(oldLimit);
        position(newPos);
View Full Code Here

        decoder.reset();

        int expectedLength = (int) (remaining() * decoder.averageCharsPerByte()) + 1;
        CharBuffer out = CharBuffer.allocate(expectedLength);
        for (;;) {
            CoderResult cr;
            if (hasRemaining()) {
                cr = decoder.decode(buf(), out, true);
            } else {
                cr = decoder.flush(out);
            }

            if (cr.isUnderflow()) {
                break;
            }

            if (cr.isOverflow()) {
                CharBuffer o = CharBuffer.allocate(out.capacity()
                        + expectedLength);
                out.flip();
                o.put(out);
                out = o;
                continue;
            }

            if (cr.isError()) {
                // Revert the buffer back to the previous state.
                limit(oldLimit);
                position(oldPos);
                cr.throwException();
            }
        }

        limit(oldLimit);
        position(end);
View Full Code Here

TOP

Related Classes of java.nio.charset.CoderResult

Copyright © 2018 www.massapicom. 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.