Package java.nio

Examples of java.nio.CharBuffer.flip()


  public void testAppendCharSequenceIINormal() throws IOException {
    CharBuffer cb = CharBuffer.allocate(10);
    cb.put('A');
    assertSame(cb, cb.append("String", 1, 3));
    assertEquals("Atr", cb.flip().toString());

    cb.append(null, 0, 1);
    assertEquals("n", cb.flip().toString());
  }
View Full Code Here


    cb.put('A');
    assertSame(cb, cb.append("String", 1, 3));
    assertEquals("Atr", cb.flip().toString());

    cb.append(null, 0, 1);
    assertEquals("n", cb.flip().toString());
  }

  public void testAppendCharSequenceII_IllegalArgument() throws IOException {
    CharBuffer cb = CharBuffer.allocate(10);
    cb.append("String", 0, 0);
View Full Code Here

  public void testReadCharBuffer() throws IOException {
    CharBuffer source = CharBuffer.wrap("String");
    CharBuffer target = CharBuffer.allocate(10);
    assertEquals(6, source.read(target));
    assertEquals("String", target.flip().toString());
    // return -1 when nothing to read
    assertEquals(-1, source.read(target));
    // NullPointerException
    try {
      assertEquals(-1, source.read(null));
View Full Code Here

      fail("should throw ReadOnlyBufferException.");
    } catch (ReadOnlyBufferException ex) {
      // expected;
    }
    // if target has no remaining, needn't to check the isReadOnly
    target.flip();
    assertEquals(0, source.read(target));
  }

  public void testReadOverflow() throws IOException {
    CharBuffer source = CharBuffer.wrap("String");
View Full Code Here

  public void testReadOverflow() throws IOException {
    CharBuffer source = CharBuffer.wrap("String");
    CharBuffer target = CharBuffer.allocate(1);
    assertEquals(1, source.read(target));
    assertEquals("S", target.flip().toString());
    assertEquals(1, source.position());
  }

  public void testReadSelf() throws Exception {
    CharBuffer source = CharBuffer.wrap("abuffer");
View Full Code Here

        CharBuffer dest = CharBuffer.
            allocate(10 + (int)(inbuf.remaining()*factor));

        while (true) {
            CoderResult result = decoder.decode(inbuf, dest, true);
            dest.flip();

            if (result.isUnderflow()) { // done reading
                // make sure there is at least one extra character
                if (dest.limit() == dest.capacity()) {
                    dest = CharBuffer.allocate(dest.capacity()+1).put(dest);
View Full Code Here

            if (result.isUnderflow()) { // done reading
                // make sure there is at least one extra character
                if (dest.limit() == dest.capacity()) {
                    dest = CharBuffer.allocate(dest.capacity()+1).put(dest);
                    dest.flip();
                }
                return dest;
            } else if (result.isOverflow()) { // buffer too small; expand
                int newCapacity =
                    10 + dest.capacity() +
View Full Code Here

                buffer = byteBuffer;
                CharBuffer cbuffer = charBuffer;
                buffer.clear();
                cbuffer.clear();
                cbuffer.put(cs.toString());
                cbuffer.flip();
                encoder.encode(cbuffer, buffer, true);
                buffer.flip();
            }
           
            byte[] bytes = new byte[buffer.limit()];
View Full Code Here

                cbuffer.clear();
                buffer.clear();
                buffer.put(bytes, start, length);
                buffer.flip();
                decoder.decode(buffer, cbuffer, true);
                cbuffer.flip();
            }
           
            return cbuffer.toString();
        }
       
View Full Code Here

        ByteBuffer srcBB = ByteBuffer.wrap(srcBL.getUnsafeBytes(), srcBL.begin(), srcBL.getRealSize());
        try {
            CharBuffer srcCB = CharBuffer.allocate((int) (srcDecoder.maxCharsPerByte() * srcBL.getRealSize()) + 1);
            CoderResult decodeResult = srcDecoder.decode(srcBB, srcCB, true);
            srcCB.flip();

            ByteBuffer destBB = ByteBuffer.allocate((int) (destEncoder.maxBytesPerChar() * srcCB.limit()) + 1);
            CoderResult encodeResult = destEncoder.encode(srcCB, destBB, true);
            destBB.flip();

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.