io.vertx.reactivex.core.buffer.Buffer类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中io.vertx.reactivex.core.buffer.Buffer类的一些代码示例,展示了Buffer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。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

@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: 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: io.reactiverse/reactive-pg-client

/**
 * Add a buffer value at the end of the tuple.
 * @param value the value
 * @return a reference to this, so the API can be used fluently
 */
public io.reactiverse.reactivex.pgclient.Tuple addBuffer(io.vertx.reactivex.core.buffer.Buffer value) { 
 delegate.addBuffer(value.getDelegate());
 return this;
}

代码示例来源: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: vietj/childprocess-vertx-ext

public void handle(io.vertx.core.buffer.Buffer event) {
  handler.handle(io.vertx.reactivex.core.buffer.Buffer.newInstance(event));
 }
});

代码示例来源:origin: tsegismont/vertx-musicstore

@Override
public void handle(RoutingContext rc) {
 Long albumId = PathUtil.parseLongParam(rc.pathParam("albumId"));
 if (albumId == null) {
  rc.next();
  return;
 }
 // Currently there's an issue with rx.Buffer as value type, so workaround with core Buffer
 LocalMap<Long, io.vertx.core.buffer.Buffer> covers = rc.vertx().sharedData().getLocalMap("covers");
 io.vertx.core.buffer.Buffer cached = covers.get(albumId);
 if (cached != null) {
  rc.response().end(Buffer.newInstance(cached));
  return;
 }
 download(albumId)
  .doOnSuccess(buffer -> covers.put(albumId, buffer.getDelegate()))
  .subscribe(rc.response()::end, rc::fail, () -> rc.fail(404));
}

代码示例来源: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: net.redpipe/redpipe-engine

VertxHttpResponse vertxResponse = new VertxHttpResponseWithWorkaround(response.getDelegate(), dispatcher.getProviderFactory(), request.method());
VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx.getDelegate(), headers, uriInfo, request.rawMethod(), dispatcher.getDispatcher(), vertxResponse, false);
if (buff.length() > 0)
 ByteBufInputStream in = new ByteBufInputStream(buff.getDelegate().getByteBuf());
 vertxRequest.setInputStream(in);

代码示例来源: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: 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: 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: reactiverse/reactive-pg-client

/**
 * Add a buffer value at the end of the tuple.
 * @param value the value
 * @return a reference to this, so the API can be used fluently
 */
public io.reactiverse.reactivex.pgclient.Tuple addBuffer(io.vertx.reactivex.core.buffer.Buffer value) { 
 delegate.addBuffer(value.getDelegate());
 return this;
}

代码示例来源:origin: reactiverse/reactive-pg-client

/**
 * Get a buffer value at <code>pos</code>.
 * @param name the column
 * @return the value or <code>null</code>
 */
public io.vertx.reactivex.core.buffer.Buffer getBuffer(String name) { 
 io.vertx.reactivex.core.buffer.Buffer ret = io.vertx.reactivex.core.buffer.Buffer.newInstance(delegate.getBuffer(name));
 return ret;
}

代码示例来源: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);
}

代码示例来源:origin: FroMage/redpipe

VertxHttpResponse vertxResponse = new VertxHttpResponseWithWorkaround(response.getDelegate(), dispatcher.getProviderFactory(), request.method());
VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx.getDelegate(), headers, uriInfo, request.rawMethod(), dispatcher.getDispatcher(), vertxResponse, false);
if (buff.length() > 0)
 ByteBufInputStream in = new ByteBufInputStream(buff.getDelegate().getByteBuf());
 vertxRequest.setInputStream(in);

代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch

/**
 * Perform an HTTP search query
 * @param indexes indexes names. If null search on all indexes
 * @param type document type separated by comma. If null search on all types
 * @param query json body query
 * @return elasticsearch response
 */
public Single<SearchResponse> search(final String indexes, final String type, final String query) {
  // index can be null _search on all index
  final StringBuilder url = new StringBuilder()
      .append('/')
      .append(indexes);
  if (type != null) {
    url.append('/').append(type);
  }
  url.append(URL_SEARCH);
  return httpClient
      .post(url.toString())
      .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
      .rxSendBuffer(Buffer.buffer(query))
      .map(response -> {
        if (response.statusCode() != HttpStatusCode.OK_200) {
          logger.error("Unable to search: url[{}] status[{}] query[{}] response[{}]",
              url.toString(), response.statusCode(), query, response.body());
          throw new ElasticsearchException("Unable to search");
        }
        return mapper.readValue(response.bodyAsString(), SearchResponse.class);
      });
}

代码示例来源:origin: com.cv4j.netdiscovery/netdiscovery-core

Buffer buffer = Buffer.buffer();
  buffer.getDelegate().appendBytes(request.getHttpRequestBody().getBody());
  httpResponseSingle = stringHttpRequest.rxSendBuffer(buffer);
} else {

代码示例来源: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();
 }
}

相关文章