本文整理了Java中io.vertx.rxjava.core.buffer.Buffer.buffer()
方法的一些代码示例,展示了Buffer.buffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.buffer()
方法的具体详情如下:
包路径:io.vertx.rxjava.core.buffer.Buffer
类名称:Buffer
方法名:buffer
[英]Create a new, empty buffer.
[中]创建一个新的空缓冲区。
代码示例来源: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 Buffer buffer(String s) {
return Buffer.buffer(s);
}
代码示例来源:origin: vert-x3/vertx-rx
@Test
public void testBufferSet() {
Buffer buf1 = Buffer.buffer("The quick brown fox jumps over the lazy dog");
Buffer buf2 = buf1.copy();
assertEquals(1, Stream.of(buf1, buf2).collect(toSet()).size());
}
代码示例来源: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 testBufferEquality() {
Buffer buf1 = Buffer.buffer("The quick brown fox jumps over the lazy dog");
Buffer buf2 = buf1.copy();
assertNotSame(buf1, buf2);
assertEquals(buf1, buf2);
}
代码示例来源: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 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 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
onListen.subscribe(
server -> vertx.createHttpClient(new HttpClientOptions()).websocket(8080, "localhost", "/some/path", ws -> {
ws.write(Buffer.buffer("foo"));
ws.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 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();
}
}
内容来源于网络,如有侵权,请联系作者删除!