Java Code Examples for org.eclipse.jetty.websocket.common.message.Utf8CharBuffer

Following code examples demonstrate how to use org.eclipse.jetty.websocket.common.message.Utf8CharBuffer from jetty. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.eclipse.jetty.websocket.common.message.Utf8CharBuffer and various code implementation of this class.
Example 1
Project : jetty Source File : Utf8CharBufferTest.java View Source Code on GitHub

    @Test
    public void testAppendUnicodeGetBuffer()
    {
        ByteBuffer buf = ByteBuffer.allocate(64);
        Utf8CharBuffer utf = Utf8CharBuffer.wrap(buf);

        byte bb[] = asUTF("Hello A\u00ea\u00f1\u00fcC");
        utf.append(bb,0,bb.length);

        ByteBuffer actual = utf.getByteBuffer();
        Assert.assertThat("Buffer length should be retained",actual.remaining(),is(bb.length));
        Assert.assertThat("Message",asString(actual),is("Hello A\u00ea\u00f1\u00fcC"));
    }
			
Example 2
Project : jetty Source File : Utf8CharBufferTest.java View Source Code on GitHub

    @Test
    public void testSimpleGetBuffer()
    {
        int bufsize = 64;
        ByteBuffer buf = ByteBuffer.allocate(bufsize);
        Utf8CharBuffer utf = Utf8CharBuffer.wrap(buf);

        int expectedSize = bufsize / 2;
        Assert.assertThat("Remaining (initial)",utf.remaining(),is(expectedSize));

        byte bb[] = asUTF("Hello World");
        utf.append(bb,0,bb.length);

        expectedSize -= bb.length;
        Assert.assertThat("Remaining (after append)",utf.remaining(),is(expectedSize));

        ByteBuffer actual = utf.getByteBuffer();
        Assert.assertThat("Buffer length",actual.remaining(),is(bb.length));

        Assert.assertThat("Message",asString(actual),is("Hello World"));
    }
			
Example 3
Project : jetty Source File : Utf8CharBufferTest.java View Source Code on GitHub

    @Test
    public void testAppendGetAppendGet()
    {
        ByteBuffer buf = ByteBuffer.allocate(128);
        Utf8CharBuffer utf = Utf8CharBuffer.wrap(buf);

        byte hellobytes[] = asUTF("Hello ");
        byte worldbytes[] = asUTF("World!");

        utf.append(hellobytes, 0, hellobytes.length);
        ByteBuffer hellobuf = utf.getByteBuffer();
        utf.append(worldbytes, 0, worldbytes.length);
        ByteBuffer worldbuf = utf.getByteBuffer();

        Assert.assertThat("Hello buffer",asString(hellobuf),is("Hello "));
        Assert.assertThat("World buffer",asString(worldbuf),is("Hello World!"));
    }
			
Example 4
Project : jetty Source File : Utf8CharBufferTest.java View Source Code on GitHub

    @Test
    public void testAppendGetClearAppendGet()
    {
        int bufsize = 128;
        ByteBuffer buf = ByteBuffer.allocate(bufsize);
        Utf8CharBuffer utf = Utf8CharBuffer.wrap(buf);

        int expectedSize = bufsize / 2;
        Assert.assertThat("Remaining (initial)",utf.remaining(),is(expectedSize));

        byte hellobytes[] = asUTF("Hello World");

        utf.append(hellobytes,0,hellobytes.length);
        ByteBuffer hellobuf = utf.getByteBuffer();

        Assert.assertThat("Remaining (after append)",utf.remaining(),is(expectedSize - hellobytes.length));
        Assert.assertThat("Hello buffer",asString(hellobuf),is("Hello World"));

        utf.clear();

        Assert.assertThat("Remaining (after clear)",utf.remaining(),is(expectedSize));

        byte whatnowbytes[] = asUTF("What Now?");
        utf.append(whatnowbytes,0,whatnowbytes.length);
        ByteBuffer whatnowbuf = utf.getByteBuffer();

        Assert.assertThat("Remaining (after 2nd append)",utf.remaining(),is(expectedSize - whatnowbytes.length));
        Assert.assertThat("What buffer",asString(whatnowbuf),is("What Now?"));
    }