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