本文整理了Java中io.vertx.rxjava.core.buffer.Buffer.toString()
方法的一些代码示例,展示了Buffer.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.toString()
方法的具体详情如下:
包路径:io.vertx.rxjava.core.buffer.Buffer
类名称:Buffer
方法名:toString
[英]Returns a String
representation of the Buffer with the UTF-8
encoding
[中]返回带有UTF-8
编码的缓冲区的String
表示形式
代码示例来源: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 Observable<JsonObject>
Observable<JsonObject> obs1 = req1.toObservable().flatMap(HttpClientResponse::toObservable).
map(buf -> new JsonObject(buf.toString("UTF-8")));
Observable<JsonObject> obs2 = req2.toObservable().flatMap(HttpClientResponse::toObservable).
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);
},
err -> {
err.printStackTrace();
});
req1.end();
req2.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.toObservable().
// Status code check and -> Observable<Buffer>
flatMap(resp -> {
if (resp.statusCode() != 200) {
throw new RuntimeException("Wrong status code " + resp.statusCode());
}
return resp.toObservable();
}).
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();
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.toObservable().
// Status code check and -> Observable<Buffer>
flatMap(resp -> {
if (resp.statusCode() != 200) {
throw new RuntimeException("Wrong status code " + resp.statusCode());
}
return Observable.just(Buffer.buffer()).mergeWith(resp.toObservable());
}).
// 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: vert-x3/vertx-rx
@Override
protected String string(Buffer buffer) {
return buffer.toString("UTF-8");
}
}
代码示例来源:origin: msoute/vertx-deploy-tools
private String retrieveAndParseMetadata(Path fileLocation, ModuleRequest request) {
Buffer b = rxVertx.fileSystem().readFileBlocking(fileLocation.toString());
return MetadataXPathUtil.getRealSnapshotVersionFromMetadata(b.toString().getBytes(), request);
}
}
代码示例来源:origin: io.devcon5.timeseries/ts-collector
void sendDatapoint(String dbname, String msg) {
LOG.trace("Sending measures length = {} Bytes ", msg.length());
this.http.post("/write?db=" + dbname, response -> {
if (response.statusCode() >= 400) {
LOG.warn("{} {}", response.statusCode(), response.statusMessage());
response.bodyHandler(data -> LOG.warn(data.toString()));
}
}).end(msg);
}
代码示例来源:origin: msoute/vertx-deploy-tools
.flatMap(buffer -> {
try {
serviceProperties.load(new ByteArrayInputStream(buffer.toString().getBytes()));
} catch (IOException e) {
LOG.error("[{} - {}]: Failed to initialize properties for module {} with error '{}'", LogConstants.DEPLOY_REQUEST, request.getId(), request.getModuleId(), e.getMessage(), e);
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testClusterSerializable() throws Exception {
io.vertx.rxjava.core.buffer.Buffer buff = io.vertx.rxjava.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.rxjava.core.buffer.Buffer.buffer("hello-world");
assertEquals(expected.length(), buff.readFromBuffer(0, expected));
assertEquals("hello-world", buff.toString());
}
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testBufferToString() {
String string = "The quick brown fox jumps over the lazy dog";
assertEquals(string, Buffer.buffer(string).toString());
}
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testWebsocketClientFlatMap() {
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.websocketStream().handler(ws -> {
ws.write(Buffer.buffer("some_content"));
ws.close();
});
server.listen(ar -> {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
Buffer content = Buffer.buffer();
client.
websocketStream(8080, "localhost", "/the_uri").
toObservable().
flatMap(WebSocket::toObservable).
forEach(content::appendBuffer, err -> fail(), () -> {
server.close();
assertEquals("some_content", content.toString("UTF-8"));
testComplete();
});
});
await();
}
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testPost() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.bodyHandler(buff -> {
assertEquals("onetwothree", buff.toString());
req.response().end();
}));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Observable<Buffer> stream = Observable.just(Buffer.buffer("one"), Buffer.buffer("two"), Buffer.buffer("three"));
Single<HttpResponse<Buffer>> single = client
.post(8080, "localhost", "/the_uri")
.rxSendStream(stream);
for (int i = 0; i < times; i++) {
single.subscribe(resp -> complete(), this::fail);
}
});
await();
} finally {
server.close();
}
}
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testHttpClientFlatMap() {
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> {
req.response().setChunked(true).end("some_content");
});
server.listen(ar -> {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
Single<HttpClientResponse> req = client.rxGetNow(8080, "localhost", "/the_uri");
Buffer content = Buffer.buffer();
req.flatMapObservable(HttpClientResponse::toObservable).forEach(
content::appendBuffer,
err -> fail(), () -> {
server.close();
assertEquals("some_content", content.toString("UTF-8"));
testComplete();
});
});
await();
}
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testWebsocketClient() {
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.websocketStream().handler(ws -> {
ws.write(Buffer.buffer("some_content"));
ws.close();
});
server.listen(ar -> {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
client.websocket(8080, "localhost", "/the_uri", ws -> {
Buffer content = Buffer.buffer();
Observable<Buffer> observable = ws.toObservable();
observable.forEach(content::appendBuffer, err -> fail(), () -> {
server.close();
assertEquals("some_content", content.toString("UTF-8"));
testComplete();
});
});
});
await();
}
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testHttpClient() {
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> {
req.response().setChunked(true).end("some_content");
});
try {
server.listen(ar -> {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
client.rxGetNow(8080, "localhost", "/the_uri").subscribe(resp -> {
Buffer content = Buffer.buffer();
Observable<Buffer> observable = resp.toObservable();
observable.forEach(content::appendBuffer, err -> fail(), () -> {
assertEquals("some_content", content.toString("UTF-8"));
testComplete();
});
});
});
await();
} finally {
server.close();
}
}
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testGet() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().setChunked(true).end("some_content"));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<Buffer>> single = client
.get(8080, "localhost", "/the_uri")
.as(BodyCodec.buffer())
.rxSend();
for (int i = 0; i < times; i++) {
single.subscribe(resp -> {
Buffer body = resp.body();
assertEquals("some_content", body.toString("UTF-8"));
complete();
}, this::fail);
}
});
await();
} finally {
server.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!