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

x33g5p2x  于2022-01-17 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(200)

本文整理了Java中io.vertx.rxjava.core.buffer.Buffer类的一些代码示例,展示了Buffer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer类的具体详情如下:
包路径:io.vertx.rxjava.core.buffer.Buffer
类名称:Buffer

Buffer介绍

[英]Most data is shuffled around inside Vert.x using buffers.

A buffer is a sequence of zero or more bytes that can read from or written to and which expands automatically as necessary to accommodate any bytes written to it. You can perhaps think of a buffer as smart byte array.

Please consult the documentation for more information on buffers.

NOTE: This class has been automatically generated from the io.vertx.core.buffer.Buffer non RX-ified interface using Vert.x codegen.
[中]大多数数据都在Vert内部混洗。x使用缓冲区。
缓冲区是一个由零个或多个字节组成的序列,可以读取或写入,并根据需要自动扩展以容纳写入它的任何字节。您也许可以将缓冲区视为智能字节数组。
有关缓冲区的更多信息,请参阅文档。
注意:此类是从io自动生成的。维特斯。果心缓冲器使用Vert的缓冲区非接收接口。x编码基因。

代码示例

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

/**
 * Create a new buffer from a string. The string will be UTF-8 encoded into the buffer.
 * @param string the string
 * @return the buffer
 */
public static io.vertx.rxjava.core.buffer.Buffer buffer(String string) { 
 io.vertx.rxjava.core.buffer.Buffer ret = io.vertx.rxjava.core.buffer.Buffer.newInstance(io.vertx.core.buffer.Buffer.buffer(string));
 return ret;
}

代码示例来源:origin: io.vertx/vertx-rx-java

@Override
 public io.vertx.core.buffer.Buffer unwrap(Buffer buffer) {
  return buffer.getDelegate();
 }
};

代码示例来源: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-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: georocket/georocket

out.write(data.getDelegate());
progress.setCurrent(bytesWritten.getAndAdd(data.length()));
if (out.writeQueueFull()) {
 file.pause();

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

@Override
protected Buffer buffer(String s) {
 return Buffer.buffer(s);
}

代码示例来源:origin: georocket/georocket

read[0] += buf.length();
if (lastOutput[0] == 0 || read[0] - lastOutput[0] > 1024 * 2048) {
 logProgress(length, read[0]);

代码示例来源:origin: io.vertx/vertx-rx-java

public static  Buffer newInstance(io.vertx.core.buffer.Buffer arg) {
  return arg != null ? new Buffer(arg) : null;
 }
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Create a new, empty buffer.
 * @return the buffer
 */
public static io.vertx.rxjava.core.buffer.Buffer buffer() { 
 io.vertx.rxjava.core.buffer.Buffer ret = io.vertx.rxjava.core.buffer.Buffer.newInstance(io.vertx.core.buffer.Buffer.buffer());
 return ret;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Same as {@link io.vertx.rxjava.core.http.HttpServerResponse#end} but writes some data to the response body before ending. If the response is not chunked and
 * no other data has been written then the @code{Content-Length} header will be automatically set.
 * @param chunk the buffer to write before ending the response
 */
public void end(io.vertx.rxjava.core.buffer.Buffer chunk) { 
 delegate.end(chunk.getDelegate());
}

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

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

public static  Buffer newInstance(io.vertx.core.buffer.Buffer arg) {
  return arg != null ? new Buffer(arg) : null;
 }
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Create a new buffer given the initial size hint.
 * <p>
 * If you know the buffer will require a certain size, providing the hint can prevent unnecessary re-allocations
 * as the buffer is written to and resized.
 * @param initialSizeHint the hint, in bytes
 * @return the buffer
 */
public static io.vertx.rxjava.core.buffer.Buffer buffer(int initialSizeHint) { 
 io.vertx.rxjava.core.buffer.Buffer ret = io.vertx.rxjava.core.buffer.Buffer.newInstance(io.vertx.core.buffer.Buffer.buffer(initialSizeHint));
 return ret;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Writes a (potentially large) piece of binary data to the connection. This data might be written as multiple frames
 * if it exceeds the maximum WebSocket frame size.
 * @param data the data to write
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.core.http.WebSocketBase writeBinaryMessage(io.vertx.rxjava.core.buffer.Buffer data) { 
 delegate.writeBinaryMessage(data.getDelegate());
 return this;
}

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

相关文章