Java Code Examples for io.vertx.core.streams.ReadStream#handler()
The following examples show how to use
io.vertx.core.streams.ReadStream#handler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainVerticle.java From okapi with Apache License 2.0 | 6 votes |
/** * Simple test to fake a _tenantPermission interface. * Captures the body, and reports it in a header. * * @param ctx routing context */ private void myPermissionHandle(RoutingContext ctx) { ReadStream<Buffer> content = ctx.request(); final Buffer incoming = Buffer.buffer(); content.handler(incoming::appendBuffer); ctx.request().endHandler(x -> { String body = incoming.toString(); body = body.replaceAll("\\s+", " "); // remove newlines etc ctx.response().putHeader("X-Tenant-Perms-Result", body); if (body.length() > 80) { body = body.substring(0, 80) + "..."; } logger.info("tenantPermissions: {}", body); ctx.response().end(); }); }
Example 2
Source File: ProxyService.java From okapi with Apache License 2.0 | 5 votes |
private void proxyStreamToBuffer(ReadStream<Buffer> stream, Buffer bcontent, Handler<Buffer> handle) { if (bcontent != null) { handle.handle(bcontent); } else { final Buffer incoming = Buffer.buffer(); stream.handler(incoming::appendBuffer); stream.endHandler(v -> handle.handle(incoming)); stream.resume(); } }
Example 3
Source File: ConfigurationStreamTest.java From vertx-config with Apache License 2.0 | 5 votes |
@Test public void testFetch(TestContext tc) { retriever = ConfigRetriever.create(vertx, addStores(new ConfigRetrieverOptions().setScanPeriod(500))); Async async = tc.async(); AtomicInteger steps = new AtomicInteger(); ReadStream<JsonObject> stream = retriever.configStream(); stream.pause(); stream.fetch(3); AtomicBoolean paused = new AtomicBoolean(); stream .handler(conf -> { String foo = conf.getString("foo"); tc.assertFalse(paused.get()); int step = steps.getAndIncrement(); if (step == 0) { tc.assertEquals(foo, "bar"); } else { tc.assertEquals(foo, "bar" + step); } if (step < 2) { } else if (step < 6) { paused.set(true); vertx.setTimer(1000, id -> { paused.set(false); stream.fetch(1); }); } else { async.complete(); } System.setProperty("foo", "bar" + (step + 1)); }); }
Example 4
Source File: ReadStreamSubscriberTestBase.java From vertx-rx with Apache License 2.0 | 4 votes |
void subscribe(ReadStream<String> sender) { sender.exceptionHandler(this::handleException); sender.endHandler(this::handleEnd); sender.handler(this::handle); }