Package java.nio

Examples of java.nio.CharBuffer.limit()


    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()
      throws CharacterCodingException, UnsupportedEncodingException {
    CharBuffer out;
View Full Code Here


    // normal case, one complete operation
    decoder.reset();
    in.rewind();
    out.rewind();
    assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, true));
    assertEquals(out.limit(), 100);
    assertEquals(out.position(), unistr.length());
    assertEquals(out.remaining(), 100 - unistr.length());
    assertEquals(out.capacity(), 100);
    assertCharBufferValue(out, unistr);
    decoder.flush(out);
View Full Code Here

    // endOfInput to false
    decoder.reset();
    in.rewind();
    out.clear();
    assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, false));
    assertEquals(out.limit(), 100);
    assertEquals(out.position(), unistr.length());
    assertEquals(out.remaining(), 100 - unistr.length());
    assertEquals(out.capacity(), 100);
    assertCharBufferValue(out, unistr);
View Full Code Here

    assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, false));
    in = ByteBuffer.wrap(unibytes);
    assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, false));
    in.rewind();
    assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, true));
    assertEquals(out.limit(), 100);
    assertTrue(out.position() > 0);
    assertEquals(out.remaining(), out.capacity() - out.position());
    assertEquals(out.capacity(), 100);
    assertCharBufferValue(out, unistr + unistr + unistr);
View Full Code Here

                while (bytes.remaining() > 0) {
                    CoderResult res = cd.decode(bytes, chars, true);
                    if (res.isMalformed() || res.isUnmappable()) {
                        return true;
                    } else if (res.isOverflow()) {
                        chars.limit(chars.position());
                        chars.rewind();
                        int c = chars.capacity() * 2;
                        CharBuffer on = CharBuffer.allocate(c);
                        on.put(chars);
                        chars = on;
View Full Code Here

        public ByteArrayCodepointIterator(byte[] bytes, Charset charset) {
            CharBuffer cb = charset.decode(ByteBuffer.wrap(bytes));
            buffer = cb.array();
            position = cb.position();
            limit = cb.limit();
        }
    }

    static class CharArrayCodepointIterator extends CodepointIterator {
        protected char[] buffer;
View Full Code Here

                    outc.write(buf);
                }
                CharBuffer cb = charset.decode(ByteBuffer.wrap(out.toByteArray()));
                buffer = cb.array();
                position = cb.position();
                limit = cb.limit();
            } catch (Exception e) {
            }
        }
    }
View Full Code Here

        decoder = provider.charsetForName("UTF-32BE").newDecoder();
        //test overflow buffer
        bs.put((byte)0x00); bs.put((byte)0x01); bs.put((byte)0xFF); bs.put((byte)0x41);
        us.put((char)0x0000);
       
        us.limit(us.position());
        us.position(0);
        bs.limit(bs.position());
        bs.position(0);
       
        try {
View Full Code Here

        us.clear();
        //test malform buffer
        bs.put((byte)0x00); bs.put((byte)0x00); bs.put((byte)0xD9); bs.put((byte)0x02);
        us.put((char)0x0000);
       
        us.limit(us.position());
        us.position(0);
        bs.limit(bs.position());
        bs.position(0);
       
        try {
View Full Code Here

        //test malform buffer
        bs.put((byte)0x00); bs.put((byte)0x00); bs.put((byte)0xFE); bs.put((byte)0xFF);
        bs.put((byte)0x10); bs.put((byte)0xFF); bs.put((byte)0xDF);
        us.put((char)0x0000);
       
        us.limit(us.position());
        us.position(0);
        bs.limit(bs.position());
        bs.position(0);
       
        try {
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.