Examples of CoderResult


Examples of java.nio.charset.CoderResult

                underflow = null;
            }
            int last = -1;
            while (cb.hasRemaining()) {
                int remaining = buffer.remaining();
                CoderResult result = charsetEncoder.encode(cb, buffer, false);
                outputStream.updateWritten(remaining - buffer.remaining());
                if (result.isOverflow() || !buffer.hasRemaining()) {
                    outputStream.flushInternal();
                    if (!buffer.hasRemaining()) {
                        error = true;
                        return;
                    }
                }
                if (result.isUnderflow()) {
                    underflow = new char[cb.remaining()];
                    cb.get(underflow);
                    return;
                }
                if (result.isError()) {
                    error = true;
                    return;
                }
                if (result.isUnmappable()) {
                    //this should not happen
                    error = true;
                    return;
                }
                if (last == cb.remaining()) {
View Full Code Here

Examples of java.nio.charset.CoderResult

        }
       
        reset();

        for (;;) {
            CoderResult cr;

            if (in.hasRemaining()) {
                cr = encoder.encode(in, out, true);
            } else {
                cr = encoder.flush(out);
            }

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

            if (cr.isOverflow()) {
                n *= 2;
                ByteBuffer o = ByteBuffer.allocate(n);
                out.flip();
                o.put(out);
                out = o;
                continue;
            }

            if (map & cr.isUnmappable()) {
                lossy = true;
                in.get();
                out.put(replacement);
                continue;
            }
            cr.throwException();
        }
        out.flip();
        return out;
    }
View Full Code Here

Examples of java.nio.charset.CoderResult

            // Initialize the char buffer
            cb.limit(cc.getEnd());
            cb.position(cc.getStart());
        }
        // Do the decoding and get the results into the byte chunk and the char chunk
        CoderResult result = encoder.encode(cb, bb, false);
        if (result.isError() || result.isMalformed()) {
            result.throwException();
        } else if (result.isOverflow()) {
            // Propagate current positions to the byte chunk and char chunk
            bc.setEnd(bb.position());
            cc.setOffset(cb.position());
        } else if (result.isUnderflow()) {
            // Propagate current positions to the byte chunk and char chunk
            bc.setEnd(bb.position());
            cc.setOffset(cb.position());
        }
    }
View Full Code Here

Examples of java.nio.charset.CoderResult

        final CharBuffer outputBuffer = this.outputBuffer;
        final ByteBuffer inputBuffer = this.inputBuffer;
        inputBuffer.flip();
        try {
            while (inputBuffer.hasRemaining()) {
                final CoderResult coderResult = decoder.decode(inputBuffer, outputBuffer, false);
                if (coderResult.isUnderflow() && outputBuffer.position() == 0) {
                    return;
                }
                outputBuffer.flip();
                try {
                    boolean ok = false;
View Full Code Here

Examples of java.nio.charset.CoderResult

        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

Examples of java.nio.charset.CoderResult

                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

Examples of java.nio.charset.CoderResult

                encoder.reset();

                int expandedState = 0;

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

                    if (cr.isUnderflow()) {
                        break;
                    }
                    if (cr.isOverflow()) {
                        if (isAutoExpand()) {
                            switch (expandedState) {
                            case 0:
                                autoExpand((int) Math.ceil(in.remaining()
                                        * encoder.averageBytesPerChar()));
                                expandedState++;
                                break;
                            case 1:
                                autoExpand((int) Math.ceil(in.remaining()
                                        * encoder.maxBytesPerChar()));
                                expandedState++;
                                break;
                            default:
                                throw new RuntimeException("Expanded by "
                                        + (int) Math.ceil(in.remaining()
                                                * encoder.maxBytesPerChar())
                                        + " but that wasn't enough for '" + val + "'");
                            }
                            continue;
                        }
                    } else {
                        expandedState = 0;
                    }
                    cr.throwException();
                }
                return this;
            }
View Full Code Here

Examples of java.nio.charset.CoderResult

                CharBuffer in = CharBuffer.wrap(val);
                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();
                }

                limit(oldLimit);

                if (position() < end) {
View Full Code Here

Examples of java.nio.charset.CoderResult

                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;
                    }

                    cr.throwException();
                }

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

Examples of java.nio.charset.CoderResult

                encoder.reset();

                int expandedState = 0;

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

                    if (position() - oldPos > maxLength) {
                        throw new IllegalArgumentException(
                                "The specified string is too long.");
                    }

                    if (cr.isUnderflow()) {
                        break;
                    }
                    if (cr.isOverflow()) {
                        if (isAutoExpand()) {
                            switch (expandedState) {
                                case 0:
                                    autoExpand((int) Math.ceil(in.remaining()
                                            * encoder.averageBytesPerChar()));
                                    expandedState++;
                                    break;
                                case 1:
                                    autoExpand((int) Math.ceil(in.remaining()
                                            * encoder.maxBytesPerChar()));
                                    expandedState++;
                                    break;
                                default:
                                    throw new RuntimeException("Expanded by "
                                            + (int) Math.ceil(in.remaining()
                                                    * encoder.maxBytesPerChar())
                                            + " but that wasn't enough for '" + val + "'");
                            }
                            continue;
                        }
                    } else {
                        expandedState = 0;
                    }
                    cr.throwException();
                }

                // Write the length field
                fill(padValue, padding - (position() - oldPos & padMask));
                int length = position() - oldPos;
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.