use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HTTPExamples method example48.
public void example48(HttpClient client) {
client.getNow("some-uri", response -> {
Buffer totalBuffer = Buffer.buffer();
response.handler(buffer -> {
System.out.println("Received a part of the response body: " + buffer.length());
totalBuffer.appendBuffer(buffer);
});
response.endHandler(v -> {
System.out.println("Total response body length is " + totalBuffer.length());
});
});
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class FileSystemExamples method asyncFileWrite.
public void asyncFileWrite() {
Vertx vertx = Vertx.vertx();
vertx.fileSystem().open("target/classes/hello.txt", new OpenOptions(), result -> {
if (result.succeeded()) {
AsyncFile file = result.result();
Buffer buff = Buffer.buffer("foo");
for (int i = 0; i < 5; i++) {
file.write(buff, buff.length() * i, ar -> {
if (ar.succeeded()) {
System.out.println("Written ok!");
} else {
System.err.println("Failed to write: " + ar.cause());
}
});
}
} else {
System.err.println("Cannot open file " + result.cause());
}
});
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class EventBusTestBase method testSendBuffer.
@Test
public void testSendBuffer() {
Buffer sent = TestUtils.randomBuffer(100);
testSend(sent, (buffer) -> {
assertEquals(sent, buffer);
// Make sure it's copied
assertFalse(sent == buffer);
});
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class DatagramTest method testSendReceiveLargePacket.
@Test
public void testSendReceiveLargePacket() {
int packetSize = 10000;
peer1 = vertx.createDatagramSocket(new DatagramSocketOptions().setSendBufferSize(packetSize));
// OSX needs 16 more
peer2 = vertx.createDatagramSocket(new DatagramSocketOptions().setReceiveBufferSize(packetSize + 16));
peer2.exceptionHandler(t -> fail(t.getMessage()));
peer2.listen(1234, "127.0.0.1", ar -> {
assertTrue(ar.succeeded());
Buffer buffer = TestUtils.randomBuffer(packetSize);
peer2.handler(packet -> {
assertEquals(buffer, packet.data());
testComplete();
});
peer1.send(buffer, 1234, "127.0.0.1", ar2 -> assertTrue(ar2.succeeded()));
});
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class DatagramTest method testBroadcast.
@Test
public void testBroadcast() {
peer1 = vertx.createDatagramSocket(new DatagramSocketOptions().setBroadcast(true));
peer2 = vertx.createDatagramSocket(new DatagramSocketOptions().setBroadcast(true));
peer2.exceptionHandler(t -> fail(t.getMessage()));
peer2.listen(1234, "0.0.0.0", ar1 -> {
assertTrue(ar1.succeeded());
Buffer buffer = TestUtils.randomBuffer(128);
peer2.handler(packet -> {
assertEquals(buffer, packet.data());
testComplete();
});
peer1.send(buffer, 1234, "255.255.255.255", ar2 -> {
assertTrue(ar2.succeeded());
});
});
await();
}
Aggregations