本文整理了Java中io.vertx.reactivex.core.buffer.Buffer.toString()
方法的一些代码示例,展示了Buffer.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.toString()
方法的具体详情如下:
包路径:io.vertx.reactivex.core.buffer.Buffer
类名称:Buffer
方法名:toString
暂无
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
// Create two requests
HttpClientRequest req1 = client.request(HttpMethod.GET, 8080, "localhost", "/");
HttpClientRequest req2 = client.request(HttpMethod.GET, 8080, "localhost", "/");
// Turn the requests responses into Flowable<JsonObject>
Flowable<JsonObject> obs1 = req1.toFlowable().flatMap(HttpClientResponse::toFlowable).
map(buf -> new JsonObject(buf.toString("UTF-8")));
Flowable<JsonObject> obs2 = req2.toFlowable().flatMap(HttpClientResponse::toFlowable).
map(buf -> new JsonObject(buf.toString("UTF-8")));
// Combine the responses with the zip into a single response
obs1.zipWith(obs2, (b1, b2) -> new JsonObject().put("req1", b1).put("req2", b2)).
subscribe(json -> {
System.out.println("Got combined result " + json);
},
Throwable::printStackTrace);
req1.end();
req2.end();
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
client.put(8080, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode());
resp.handler(buf -> System.out.println(buf.toString("UTF-8")));
}).setChunked(true).putHeader("Content-Type", "text/plain").write("hello").end();
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/");
req.toFlowable().
// Status code check and -> Flowable<Buffer>
flatMap(resp -> {
if (resp.statusCode() != 200) {
throw new RuntimeException("Wrong status code " + resp.statusCode());
}
return resp.toFlowable();
}).
subscribe(data -> System.out.println("Server content " + data.toString("UTF-8")));
// End request
req.end();
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/");
req.toFlowable().
// Status code check and -> Flowable<Buffer>
flatMap(resp -> {
if (resp.statusCode() != 200) {
throw new RuntimeException("Wrong status code " + resp.statusCode());
}
return Flowable.just(Buffer.buffer()).mergeWith(resp.toFlowable());
}).
// Reduce all buffers in a single buffer
reduce(Buffer::appendBuffer).
// Turn in to a string
map(buffer -> buffer.toString("UTF-8")).
// Get a single buffer
subscribe(data -> System.out.println("Server content " + data));
// End request
req.end();
}
}
代码示例来源:origin: Cognifide/knotx
private void traceServiceCall(Buffer results) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Service call returned <{}>", results.toString());
}
}
}
代码示例来源:origin: io.knotx.acme/acme-forms-adapter-http
private void traceServiceCall(Buffer results) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Service call returned <{}>", results.toString());
}
}
}
代码示例来源:origin: io.knotx/knotx-databridge-adapter-http
private void traceServiceCall(Buffer results) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Service call returned <{}>", results.toString());
}
}
}
代码示例来源:origin: FroMage/redpipe
private void send(Mail email, Buffer text, Buffer html) {
SentMail sentMail = new SentMail(email, text.toString(), html != null ? html.toString() : null);
if (email.to != null) {
for (String to : email.to) {
send(sentMail, to);
}
}
if (email.cc != null) {
for (String to : email.cc) {
send(sentMail, to);
}
}
if (email.bcc != null) {
for (String to : email.bcc) {
send(sentMail, to);
}
}
}
代码示例来源:origin: net.redpipe/redpipe-engine
private void send(Mail email, Buffer text, Buffer html) {
SentMail sentMail = new SentMail(email, text.toString(), html != null ? html.toString() : null);
if (email.to != null) {
for (String to : email.to) {
send(sentMail, to);
}
}
if (email.cc != null) {
for (String to : email.cc) {
send(sentMail, to);
}
}
if (email.bcc != null) {
for (String to : email.bcc) {
send(sentMail, to);
}
}
}
代码示例来源:origin: FroMage/redpipe
private Single<String> get(Vertx vertx, URI uri){
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Buffer>> responseHandler =
client.get(uri.getPort(), uri.getHost(), uri.getPath()).rxSend();
return responseHandler.map(response -> response.body().toString())
.doAfterTerminate(() -> client.close());
}
代码示例来源:origin: FroMage/redpipe
@Path("7")
@GET
public CompletionStage<String> hello7(@Context Vertx vertx){
io.vertx.reactivex.core.Vertx rxVertx = io.vertx.reactivex.core.Vertx.newInstance(vertx);
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
CompletableFuture<String> ret = new CompletableFuture<>();
responseHandler
.doAfterTerminate(() -> client.close())
.subscribe(body -> {
System.err.println("Got body");
ret.complete(body.body().toString());
});
System.err.println("Created client");
return ret;
}
代码示例来源:origin: FroMage/redpipe
@Path("coroutines/1")
@GET
public Single<Response> helloAsync(@Context io.vertx.reactivex.core.Vertx rxVertx){
return Fibers.fiber(() -> {
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
System.err.println("Got response");
HttpResponse<io.vertx.reactivex.core.buffer.Buffer> httpResponse = Fibers.await(responseHandler);
System.err.println("Got body");
client.close();
return Response.ok(httpResponse.body().toString()).build();
});
}
}
代码示例来源:origin: FroMage/redpipe
@Path("8user")
@Produces("text/json")
@GET
public Single<DataClass> hello8User(@Context io.vertx.reactivex.core.Vertx rxVertx){
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
System.err.println("Created client");
return responseHandler.map(body -> {
System.err.println("Got body");
return new DataClass(body.body().toString());
}).doAfterTerminate(() -> client.close());
}
代码示例来源:origin: FroMage/redpipe
@Path("6")
@GET
public void hello6(@Suspended final AsyncResponse asyncResponse,
// Inject the Vertx instance
@Context Vertx vertx){
io.vertx.reactivex.core.Vertx rxVertx = io.vertx.reactivex.core.Vertx.newInstance(vertx);
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
responseHandler
.doAfterTerminate(() -> client.close())
.subscribe(body -> {
System.err.println("Got body");
asyncResponse.resume(Response.ok(body.body().toString()).build());
});
System.err.println("Created client");
}
代码示例来源:origin: FroMage/redpipe
@Path("8")
@GET
public Single<String> hello8(@Context io.vertx.reactivex.core.Vertx rxVertx){
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
System.err.println("Created client");
return responseHandler.map(body -> {
System.err.println("Got body");
return body.body().toString();
}).doAfterTerminate(() -> client.close());
}
代码示例来源:origin: net.redpipe/redpipe-engine
@Override
public Completable send(Mail email) {
Single<Optional<Buffer>> htmlRender = email.renderHtml().map(buffer -> Optional.of(buffer)).toSingle(Optional.empty());
Single<Buffer> textRender = email.renderText();
return Single.zip(textRender, htmlRender, (text, html) -> {
MailMessage message = new MailMessage();
message.setFrom(email.from);
if(email.to != null)
message.setTo(Arrays.asList(email.to));
if(email.cc != null)
message.setCc(Arrays.asList(email.cc));
if(email.bcc != null)
message.setBcc(Arrays.asList(email.bcc));
message.setSubject(email.subject);
message.setText(text.toString());
if(html.isPresent())
message.setHtml(html.get().toString());
return mailClient.rxSendMail(message).ignoreElement();
}).flatMapCompletable(c -> c);
}
}
代码示例来源:origin: io.vertx/vertx-rx-java2
@Test
public void testClusterSerializable() throws Exception {
io.vertx.reactivex.core.buffer.Buffer buff = io.vertx.reactivex.core.buffer.Buffer.buffer("hello-world");
Buffer actual = Buffer.buffer();
buff.writeToBuffer(actual);
Buffer expected = Buffer.buffer();
Buffer.buffer("hello-world").writeToBuffer(expected);
assertEquals(expected, actual);
buff = io.vertx.reactivex.core.buffer.Buffer.buffer("hello-world");
assertEquals(expected.length(), buff.readFromBuffer(0, expected));
assertEquals("hello-world", buff.toString());
}
}
代码示例来源:origin: io.vertx/vertx-rx-java2
@Test
public void testBufferToString() {
String string = "The quick brown fox jumps over the lazy dog";
assertEquals(string, Buffer.buffer(string).toString());
}
代码示例来源:origin: Cognifide/knotx
private void testGetRequest(VertxTestContext context, Vertx vertx, String url,
String expectedResult) {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Buffer>> httpResponseSingle = client
.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url).rxSend();
subscribeToResult_shouldSucceed(context, httpResponseSingle,
resp -> {
assertEquals(expectedResult, resp.body().toString(),
"Wrong engines processed request, expected " + expectedResult);
assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
resp.getHeader(EXPECTED_RESPONSE_HEADER));
});
}
代码示例来源:origin: Cognifide/knotx
private void testGetRequestOldClient(VertxTestContext context, Vertx vertx, String url, String expectedResult) {
HttpClient client = vertx.createHttpClient();
client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url,
resp -> resp.bodyHandler(body -> {
assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
resp.getHeader(EXPECTED_RESPONSE_HEADER));
try {
assertEquals(expectedResult, body.toString(),
"Wrong engines processed request, expected " + expectedResult);
} catch (Exception e) {
context.failNow(e);
}
client.close();
context.completeNow();
}));
}
内容来源于网络,如有侵权,请联系作者删除!