本文整理了Java中io.vertx.reactivex.core.buffer.Buffer.buffer()
方法的一些代码示例,展示了Buffer.buffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.buffer()
方法的具体详情如下:
包路径:io.vertx.reactivex.core.buffer.Buffer
类名称:Buffer
方法名: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.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: io.knotx/knotx-core
private Observable<ClientResponse> processResponse(final HttpClientResponse response, final RequestOptions httpRequestData) {
return Observable.just(Buffer.buffer())
.mergeWith(response.toObservable())
.reduce(Buffer::appendBuffer)
.toObservable()
.map(buffer -> toResponse(buffer, response, httpRequestData));
}
代码示例来源:origin: Cognifide/knotx
private Observable<ClientResponse> processResponse(final HttpClientResponse response, final RequestOptions httpRequestData) {
return Observable.just(Buffer.buffer())
.mergeWith(response.toObservable())
.reduce(Buffer::appendBuffer)
.toObservable()
.map(buffer -> toResponse(buffer, response, httpRequestData));
}
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
@Override
public Single<BulkResponse> bulk(final List<String> data) {
if (data != null && !data.isEmpty()) {
String content = data.stream().collect(Collectors.joining());
return httpClient
.post(URL_BULK)
.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-ndjson")
.rxSendBuffer(Buffer.buffer(content))
.map(response -> {
if (response.statusCode() != HttpStatusCode.OK_200) {
logger.error("Unable to bulk index data: status[{}] data[{}] response[{}]",
response.statusCode(), content, response.body());
throw new ElasticsearchException("Unable to bulk index data");
}
return mapper.readValue(response.bodyAsString(), BulkResponse.class);
});
}
return Single.never();
}
代码示例来源:origin: io.gravitee.am.gateway/gravitee-am-gateway-reactor
private void sendNotFound(HttpServerResponse serverResponse) {
// Send a NOT_FOUND HTTP status code (404)
serverResponse.setStatusCode(HttpStatusCode.NOT_FOUND_404);
String message = environment.getProperty("http.errors[404].message", "");
serverResponse.headers().set(HttpHeaders.CONTENT_LENGTH, Integer.toString(message.length()));
serverResponse.headers().set(HttpHeaders.CONTENT_TYPE, "text/plain");
serverResponse.headers().set(HttpHeaders.CONNECTION, HttpHeadersValues.CONNECTION_CLOSE);
serverResponse.write(Buffer.buffer(message));
serverResponse.end();
}
代码示例来源:origin: gravitee-io/graviteeio-access-management
private void sendNotFound(HttpServerResponse serverResponse) {
// Send a NOT_FOUND HTTP status code (404)
serverResponse.setStatusCode(HttpStatusCode.NOT_FOUND_404);
String message = environment.getProperty("http.errors[404].message", "");
serverResponse.headers().set(HttpHeaders.CONTENT_LENGTH, Integer.toString(message.length()));
serverResponse.headers().set(HttpHeaders.CONTENT_TYPE, "text/plain");
serverResponse.headers().set(HttpHeaders.CONNECTION, HttpHeadersValues.CONNECTION_CLOSE);
serverResponse.write(Buffer.buffer(message));
serverResponse.end();
}
代码示例来源:origin: io.vertx/vertx-rx-java2
@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: 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.knotx.acme/acme-forms-adapter-http
private Single<Buffer> toBody(HttpResponse<Buffer> response) {
if (response.body() != null) {
return Single.just(response.body());
} else {
LOGGER.warn("Service returned empty body");
return Single.just(Buffer.buffer());
}
}
代码示例来源:origin: io.knotx/knotx-databridge-adapter-http
private Single<Buffer> toBody(HttpResponse<Buffer> response) {
if (response.body() != null) {
return Single.just(response.body());
} else {
LOGGER.warn("Service returned empty body");
return Single.just(Buffer.buffer());
}
}
代码示例来源:origin: Cognifide/knotx
private Single<Buffer> toBody(HttpResponse<Buffer> response) {
if (response.body() != null) {
return Single.just(response.body());
} else {
LOGGER.warn("Service returned empty body");
return Single.just(Buffer.buffer());
}
}
代码示例来源:origin: Cognifide/knotx
@Test
public void handleRepositoryResponse_whenResponseIsError_expectErrorResponse() {
when(clientResponse.getStatusCode()).thenReturn(400);
when(clientResponse.getHeaders()).thenReturn(MultiMap.caseInsensitiveMultiMap());
when(clientResponse.getBody()).thenReturn(Buffer.buffer().getDelegate());
when(routingContext.response()).thenReturn(httpServerResponse);
tested.handleRepositoryResponse(clientResponse, routingContext, repositoryEntry, knotContext);
verify(routingContext, times(0)).next();
verify(httpServerResponse, times(1)).setStatusCode(400);
verify(httpServerResponse, times(1)).end(any(Buffer.class));
}
}
代码示例来源:origin: Cognifide/knotx
@Test
public void handleRepositoryResponse_whenResponseIsSuccessAndShouldNotBeProcessed_expectResponse() {
when(clientResponse.getStatusCode()).thenReturn(200);
when(repositoryEntry.isDoProcessing()).thenReturn(false);
when(clientResponse.getHeaders()).thenReturn(MultiMap.caseInsensitiveMultiMap());
when(clientResponse.getBody()).thenReturn(Buffer.buffer().getDelegate());
when(routingContext.response()).thenReturn(httpServerResponse);
tested.handleRepositoryResponse(clientResponse, routingContext, repositoryEntry, knotContext);
verify(routingContext, times(0)).next();
verify(httpServerResponse, times(1)).setStatusCode(200);
verify(httpServerResponse, times(1)).end(any(Buffer.class));
}
代码示例来源:origin: io.gravitee.am.identityprovider/gravitee-am-identityprovider-oauth2-generic
private Maybe<String> authenticate(Authentication authentication) {
// prepare body request parameters
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId()));
urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret()));
urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI)));
urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials()));
urlParameters.add(new BasicNameValuePair(GRANT_TYPE, "authorization_code"));
String bodyRequest = URLEncodedUtils.format(urlParameters);
return client.postAbs(configuration.getAccessTokenUri())
.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length()))
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.rxSendBuffer(Buffer.buffer(bodyRequest))
.toMaybe()
.map(httpResponse -> {
if (httpResponse.statusCode() != 200) {
throw new BadCredentialsException(httpResponse.statusMessage());
}
return httpResponse.bodyAsJsonObject().getString("access_token");
});
}
代码示例来源:origin: gravitee-io/graviteeio-access-management
private Maybe<String> authenticate(Authentication authentication) {
// prepare body request parameters
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId()));
urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret()));
urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI)));
urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials()));
String bodyRequest = URLEncodedUtils.format(urlParameters);
return client.postAbs(configuration.getAccessTokenUri())
.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length()))
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.rxSendBuffer(Buffer.buffer(bodyRequest))
.toMaybe()
.map(httpResponse -> {
if (httpResponse.statusCode() != 200) {
throw new BadCredentialsException(httpResponse.statusMessage());
}
Map<String, String> bodyResponse = URLEncodedUtils.format(httpResponse.bodyAsString());
return bodyResponse.get("access_token");
});
}
代码示例来源:origin: io.gravitee.am.identityprovider/gravitee-am-identityprovider-github
private Maybe<String> authenticate(Authentication authentication) {
// prepare body request parameters
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId()));
urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret()));
urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI)));
urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials()));
String bodyRequest = URLEncodedUtils.format(urlParameters);
return client.postAbs(configuration.getAccessTokenUri())
.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length()))
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.rxSendBuffer(Buffer.buffer(bodyRequest))
.toMaybe()
.map(httpResponse -> {
if (httpResponse.statusCode() != 200) {
throw new BadCredentialsException(httpResponse.statusMessage());
}
Map<String, String> bodyResponse = URLEncodedUtils.format(httpResponse.bodyAsString());
return bodyResponse.get("access_token");
});
}
代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch
@Override
public Completable putPipeline(String pipelineName, String pipeline) {
return httpClient
.put(URL_INGEST + '/' + pipelineName)
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.rxSendBuffer(Buffer.buffer(pipeline))
.flatMapCompletable(response -> {
switch (response.statusCode()) {
case HttpStatusCode.OK_200:
return Completable.complete();
case HttpStatusCode.BAD_REQUEST_400:
logger.warn("Unable to create ES pipeline: {}", pipelineName);
break;
default:
logger.error("Unable to put pipeline: status[{}] pipeline[{}] response[{}]",
response.statusCode(), pipeline, response.body());
break;
}
return Completable.error(new ElasticsearchException("Unable to create ES pipeline: " + pipelineName));
});
}
代码示例来源: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: io.gravitee.elasticsearch/gravitee-common-elasticsearch
@Override
public Completable putTemplate(String templateName, String template) {
return httpClient
.put(URL_TEMPLATE + '/' + templateName)
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.rxSendBuffer(Buffer.buffer(template))
.flatMapCompletable(response -> {
if (response.statusCode() != HttpStatusCode.OK_200) {
logger.error("Unable to put template mapping: status[{}] template[{}] response[{}]",
response.statusCode(), template, response.body());
return Completable.error(new ElasticsearchException("Unable to put template mapping"));
}
return Completable.complete();
});
}
代码示例来源:origin: io.vertx/vertx-rx-java2
@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);
}
内容来源于网络,如有侵权,请联系作者删除!