Package java.nio

Examples of java.nio.CharBuffer.limit()


                //             been decoded and no more.
                if (charBuf.limit() == charBuf.capacity()) {
                    buffer = charBuf.array();
                } else {
                    buffer = new char[charBuf.limit()];
                    charBuf.get(buffer, 0, charBuf.limit()).position(0);
                }

                return buffer;

            } catch (IllegalStateException ile) {
View Full Code Here


                        charBuffer = decoder.decode(buf);
                    } catch (CharacterCodingException e) {
                        throw Utils.asRuntime(e);
                    }
                    buf.limit(buf.capacity());
                    String s = new String(charBuffer.array(), charBuffer.arrayOffset(), charBuffer.limit());
                    buf.position(0);
                    return s;
                } else {
                    return "";
                }
View Full Code Here

                                      : m_byteBuffer;

                // Since ASCII is single-byte, retrict encoder character consumption
                // to at most 'len' characters' to produce at most len ASCII
                // characters
                int cbLimit     = cb.limit();
                int cbPosistion = cb.position();

                cb.limit(cbPosistion + len);
                bb.clear();
View Full Code Here

                // to at most 'len' characters' to produce at most len ASCII
                // characters
                int cbLimit     = cb.limit();
                int cbPosistion = cb.position();

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

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

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

                // Restore the old limit so the buffer gets topped up
                // when required.
View Full Code Here

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

                // Restore the old limit so the buffer gets topped up
                // when required.
View Full Code Here

                    m_encoder.encode(cb, bb, false);
                }

                // Restore the old limit so the buffer gets topped up
                // when required.
                cb.limit(cbLimit);
                bb.flip();

                bytesRead = bb.limit();

                if (bytesRead == 0) {
View Full Code Here

      tmpcb.rewind();

      baseEncoder.reset();

      for (int pos = tmpcb.position(); pos < tmpcb.limit(); pos++) {
        char c = tmpcb.get (pos);
        if ( c >= 128 ){
          if (toCp347.containsKey(new Integer(c)))
            tmpcb.put (pos,(char)(((Integer)toCp347.get(new Integer((int)c))).intValue()));
          else
View Full Code Here

          buffer.flip();

          logger.debug("read {} characters", buffer.remaining());

          counterGroup.addAndGet("characters.received",
              Long.valueOf(buffer.limit()));

          builder.append(buffer.array(), buffer.position(), buffer.length());
        }

        if (builder.charAt(builder.length() - 1) == '\n') {
View Full Code Here

    // normal case
    ByteBuffer in = ByteBuffer.wrap(getUnibytes());
    out = decoder.decode(in);
    assertEquals(out.position(), 0);
    assertEquals(out.limit(), unistr.length());
    assertEquals(out.remaining(), unistr.length());
    assertEquals(new String(out.array(), 0, out.limit()), unistr);
  }

  public void testDecodeByteBufferException()
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.