Search in sources :

Example 71 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testAppendBytes.

@Test
public void testAppendBytes() throws Exception {
    int bytesLen = 100;
    byte[] bytes = TestUtils.randomByteArray(bytesLen);
    Buffer b = Buffer.buffer();
    b.appendBytes(bytes);
    assertEquals(b.length(), bytes.length);
    assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
    b.appendBytes(bytes);
    assertEquals(b.length(), 2 * bytes.length);
    assertNullPointerException(() -> b.appendBytes(null));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 72 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testGetString.

@Test
public void testGetString() throws Exception {
    String str = TestUtils.randomAlphaString(100);
    // encode ascii as UTF-8 so one byte per char
    Buffer b = Buffer.buffer(str, "UTF-8");
    assertEquals(100, b.length());
    String substr = b.getString(10, 20);
    assertEquals(str.substring(10, 20), substr);
    substr = b.getString(10, 20, "UTF-8");
    assertEquals(str.substring(10, 20), substr);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 73 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testAppendByte2.

@Test
public void testAppendByte2() throws Exception {
    int bytesLen = 100;
    Buffer b = Buffer.buffer(TestUtils.randomByteArray(bytesLen));
    b.setByte(b.length(), (byte) 9);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 74 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testGetSetMedium.

private void testGetSetMedium(boolean isLE) throws Exception {
    int numInts = 100;
    Buffer b = Buffer.buffer(numInts * 3);
    for (int i = 0; i < numInts; i++) {
        if (isLE) {
            b.setMediumLE(i * 3, MEDIUM_MAX_VALUE + i);
        } else {
            b.setMedium(i * 3, MEDIUM_MAX_VALUE + i);
        }
    }
    for (int i = 0; i < numInts; i++) {
        if (isLE) {
            assertEquals((MEDIUM_MAX_VALUE + i - MEDIUM_MAX_VALUE), b.getMediumLE(i * 3));
        } else {
            assertEquals((MEDIUM_MAX_VALUE + i - MEDIUM_MAX_VALUE), b.getMedium(i * 3));
        }
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer)

Example 75 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testToString.

@Test
public void testToString() throws Exception {
    String str = TestUtils.randomUnicodeString(100);
    Buffer buff = Buffer.buffer(str);
    assertEquals(str, buff.toString());
//TODO toString with encoding
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

Buffer (io.vertx.core.buffer.Buffer)1052 Test (org.junit.Test)604 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)256 Future (io.vertx.core.Future)253 AtomicReference (java.util.concurrent.atomic.AtomicReference)237 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)235 Handler (io.vertx.core.Handler)230 Vertx (io.vertx.core.Vertx)185 TestUtils (io.vertx.test.core.TestUtils)177 JsonObject (io.vertx.core.json.JsonObject)172 TimeUnit (java.util.concurrent.TimeUnit)161 CountDownLatch (java.util.concurrent.CountDownLatch)153 List (java.util.List)152 Consumer (java.util.function.Consumer)149 Function (java.util.function.Function)142 ReadStream (io.vertx.core.streams.ReadStream)139 Context (io.vertx.core.Context)135 ArrayList (java.util.ArrayList)132 MultiMap (io.vertx.core.MultiMap)130 Assume (org.junit.Assume)130