use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class BufferTest method testAppendByte.
@Test
public void testAppendByte() throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
Buffer b = Buffer.buffer();
for (int i = 0; i < bytesLen; i++) {
b.appendByte(bytes[i]);
}
assertEquals(b.length(), bytes.length);
assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes()));
for (int i = 0; i < bytesLen; i++) {
b.appendByte(bytes[i]);
}
assertEquals(b.length(), 2 * bytes.length);
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class BufferTest method testSetBytesBuffer.
private void testSetBytesBuffer(Buffer buff) throws Exception {
Buffer b = TestUtils.randomBuffer(100);
buff.setBuffer(50, b);
byte[] b2 = buff.getBytes(50, 150);
assertEquals(b, Buffer.buffer(b2));
byte[] b3 = TestUtils.randomByteArray(100);
buff.setBytes(50, b3);
byte[] b4 = buff.getBytes(50, 150);
assertEquals(Buffer.buffer(b3), Buffer.buffer(b4));
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class BufferTest method testGetBytes2.
@Test
public void testGetBytes2() throws Exception {
byte[] bytes = TestUtils.randomByteArray(100);
Buffer b = Buffer.buffer(bytes);
byte[] sub = new byte[bytes.length / 2];
System.arraycopy(bytes, bytes.length / 4, sub, 0, bytes.length / 2);
assertTrue(TestUtils.byteArraysEqual(sub, b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2)));
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http2ConnectionBase method onPingAckRead.
@Override
public synchronized void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) {
Handler<AsyncResult<Buffer>> handler = pongHandlers.poll();
if (handler != null) {
context.executeFromIO(() -> {
Buffer buff = Buffer.buffer(safeBuffer(data, ctx.alloc()));
handler.handle(Future.succeededFuture(buff));
});
}
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class WebSocketImplBase method writePartialMessage.
/**
* Splits the provided buffer into multiple frames (which do not exceed the maximum web socket frame size)
* and writes them in order to the socket.
*/
private void writePartialMessage(FrameType frameType, Buffer data, int offset) {
int end = offset + maxWebSocketFrameSize;
boolean isFinal;
if (end >= data.length()) {
end = data.length();
isFinal = true;
} else {
isFinal = false;
}
Buffer slice = data.slice(offset, end);
WebSocketFrame frame;
if (offset == 0 || !supportsContinuation) {
frame = new WebSocketFrameImpl(frameType, slice.getByteBuf(), isFinal);
} else {
frame = WebSocketFrame.continuationFrame(slice, isFinal);
}
writeFrame(frame);
int newOffset = offset + maxWebSocketFrameSize;
if (!isFinal) {
writePartialMessage(frameType, data, newOffset);
}
}
Aggregations