Package java.nio.charset

Examples of java.nio.charset.CoderResult


            // Skip over the problem characters
            for (int i = 0; i < cr.length(); i++) {
                chars.get();
            }
            // Clear the coder result
            CoderResult tmp = cr;
            cr = null;
            // ... and report the error using the appropriate exception.
            tmp.throwException();
        }
    }
View Full Code Here


        synchronized (decoder) {
            final CharBuffer outputBuffer = this.outputBuffer;
            final ByteBuffer inputBuffer = this.inputBuffer;
            inputBuffer.flip();
            for (;;) {
                final CoderResult coderResult = decoder.decode(inputBuffer, outputBuffer, false);
                if (coderResult.isOverflow()) {
                    outputBuffer.flip();
                    boolean ok = false;
                    try {
                        writer.write(outputBuffer.array(), outputBuffer.arrayOffset(), outputBuffer.remaining());
                        ok = true;
                    } finally {
                        if (! ok) {
                            inputBuffer.clear();
                        }
                        outputBuffer.clear();
                    }
                } else if (coderResult.isUnderflow()) {
                    inputBuffer.compact();
                    return;
                }
            }
        }
View Full Code Here

  {
    if (rest != ERT.NIL) {
      return rest.cons(EBinary.make(data));
    }
   
    CoderResult res;
    do {
      res = decoder.decode(data, buffer, endOfInput);
      if (!handle(res))
        fail(new PartialDecodingException(data.position()));
    } while (res == CoderResult.OVERFLOW);
View Full Code Here

            if (x <= sizeTable[i]) return i + 1;
    }

    public static void decode(CharsetDecoder charsetDecoder, ByteBuffer byteBuf, CharBuffer charByte) {
        try {
            CoderResult cr = charsetDecoder.decode(byteBuf, charByte, true);

            if (!cr.isUnderflow()) {
                cr.throwException();
            }

            cr = charsetDecoder.flush(charByte);

            if (!cr.isUnderflow()) {
                cr.throwException();
            }
        } catch (CharacterCodingException x) {
            // Substitution is always enabled,
            // so this shouldn't happen
            // TODO
View Full Code Here

                cb.limit(cbPosistion + len);
                bb.clear();

                int         bbPosition = bb.position();
                CoderResult result     = m_encoder.encode(cb, bb, false);

                if (bbPosition == bb.position() && result.isUnderflow()) {

                    // surrogate character time
                    cb.limit(cb.limit() + 1);
                    m_encoder.encode(cb, bb, false);
                }
View Full Code Here

    if ( n == 0 && in.remaining() == 0 )
      return out;

    encoder.reset();
    while ( true ) {
      CoderResult cr = in.hasRemaining() ? encoder.encode(in, out, true) : CoderResult.UNDERFLOW;
      if ( cr.isUnderflow() )
        cr = encoder.flush(out);

      if ( cr.isUnderflow() )
        break;

      if ( cr.isOverflow() ) {
        n = 2 * n + 1;    // Ensure progress; n might be 0!
        ByteBuffer o = BufferUtils.createByteBuffer(n);
        out.flip();
        o.put(out);
        out = o;
        continue;
      }

      try {
        cr.throwException();
      } catch (CharacterCodingException e) {
        throw new RuntimeException(e);
      }
    }
    out.flip();
View Full Code Here

            if (!buffer.hasRemaining()) {
                outputStream.flush();
            }
            while (cb.hasRemaining()) {
                int remaining = buffer.remaining();
                CoderResult result = charsetEncoder.encode(cb, buffer, false);
                outputStream.updateWritten(remaining - buffer.remaining());
                if(result.isOverflow()) {
                    outputStream.flush();
                }
            }
        } catch (IOException e) {
            error = true;
View Full Code Here

    ce.reset();
    ByteBuffer bb = ByteBuffer.wrap(ba);
    CharBuffer cb = CharBuffer.wrap(src, off, len);
    try {
      CoderResult cr = ce.encode(cb, bb, true);
      if (!cr.isUnderflow())
        cr.throwException();
      cr = ce.flush(bb);
      if (!cr.isUnderflow())
        cr.throwException();
      return bb;
    } catch (CharacterCodingException x) {
      // Substitution is always enabled,
      // so this shouldn't happen
      throw new Error(x);
View Full Code Here

    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();
            }
            cr = encoder.flush(dst);
            if (!cr.isUnderflow()) {
                cr.throwException();
            }
        } catch (CharacterCodingException x) {
            throw new IllegalStateException(x);
        }
        dst.flip();
View Full Code Here

    static String decodeString(ByteBuffer src, Charset charset) {
        final CharsetDecoder decoder = CharsetUtil.getDecoder(charset);
        final CharBuffer dst = CharBuffer.allocate(
                (int) ((double) src.remaining() * decoder.maxCharsPerByte()));
        try {
            CoderResult cr = decoder.decode(src, dst, true);
            if (!cr.isUnderflow()) {
                cr.throwException();
            }
            cr = decoder.flush(dst);
            if (!cr.isUnderflow()) {
                cr.throwException();
            }
        } catch (CharacterCodingException x) {
            throw new IllegalStateException(x);
        }
        return dst.flip().toString();
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.