当前位置: 首页>>代码示例>>Java>>正文


Java Buffer类代码示例

本文整理汇总了Java中io.vertx.core.buffer.Buffer的典型用法代码示例。如果您正苦于以下问题:Java Buffer类的具体用法?Java Buffer怎么用?Java Buffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Buffer类属于io.vertx.core.buffer包,在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Override
public void handle(@NotNull RoutingContext context) {
  context.vertx().<Buffer>executeBlocking(future -> {
    try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) {
      new ProtobufFormatter(registry.metricFamilySamples()).write(output);
      future.complete(Buffer.buffer(output.toByteArray()));
    } catch (IOException e) {
      future.fail(e);
    }
  }, false, result -> {
    if (result.succeeded()) {
      context.response()
          .setStatusCode(HttpResponseStatus.OK.code())
          .putHeader("Content-Type", ProtobufFormatter.CONTENT_TYPE)
          .end(result.result());
    } else {
      context.fail(result.cause());
    }
  });
}
 
开发者ID:nolequen,项目名称:vertx-prometheus-metrics,代码行数:21,代码来源:MetricsProtobufHandler.java

示例2: login

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Override
protected void login(final Future<AuthInfo> futureAuthinfo) {
	final WebClientOptions wco = new WebClientOptions();
	final String proxyHost = this.getAuthConfig().getProxy();
	final int proxyPort = this.getAuthConfig().getProxyPort();
	if ((proxyHost != null) && (proxyPort > 0)) {
		final ProxyOptions po = new ProxyOptions();
		wco.setProxyOptions(po);
		po.setHost(proxyHost).setPort(proxyPort);
	}
	wco.setUserAgent("SDFC VertX Authenticator");
	wco.setTryUseCompression(true);
	final WebClient authClient = WebClient.create(this.vertx, wco);
	final Buffer body = this.getAuthBody(this.getAuthConfig().getSfdcUser(),
			this.getAuthConfig().getSfdcPassword());
	if (!this.shuttingDown && !this.shutdownCompleted) {
		authClient.post(Constants.TLS_PORT, this.getAuthConfig().getServerURL(), Constants.AUTH_SOAP_LOGIN)
				.putHeader("Content-Type", "text/xml").ssl(true).putHeader("SOAPAction", "Login")
				.putHeader("PrettyPrint", "Yes").sendBuffer(body, postReturn -> {
					this.resultOfAuthentication(postReturn, futureAuthinfo);
				});
	} else {
		this.shutdownCompleted = true;
		futureAuthinfo.fail("Auth disruped by stop command");
	}
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:27,代码来源:SoapApi.java

示例3: writeInContext

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
protected void writeInContext() {
  CompositeByteBuf cbb = ByteBufAllocator.DEFAULT.compositeBuffer();
  for (;;) {
    ByteBuf buf = writeQueue.poll();
    if (buf == null) {
      break;
    }

    writeQueueSize.decrementAndGet();
    cbb.addComponent(true, buf);

    if (cbb.numComponents() == cbb.maxNumComponents()) {
      netSocket.write(Buffer.buffer(cbb));
      cbb = ByteBufAllocator.DEFAULT.compositeBuffer();
    }
  }
  if (cbb.isReadable()) {
    netSocket.write(Buffer.buffer(cbb));
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:TcpConnection.java

示例4: download

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Override
public FdfsClient download(FdfsFileId fileId, long offset, long bytes, Handler<AsyncResult<Buffer>> handler) {
	getTracker().setHandler(tracker -> {
		if (tracker.succeeded()) {
			tracker.result().getFetchStorage(fileId, storage -> {
				if (storage.succeeded()) {
					storage.result().download(fileId, offset, bytes, download -> {
						handler.handle(download);
					});
				} else {
					handler.handle(Future.failedFuture(storage.cause()));
				}
			});
		} else {
			handler.handle(Future.failedFuture(tracker.cause()));
		}
	});

	return this;
}
 
开发者ID:gengteng,项目名称:vertx-fastdfs-client,代码行数:21,代码来源:FdfsClientImpl.java

示例5: gossip2Seed

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
private void gossip2Seed(Buffer buffer) {
    int size = settings.getSeedMembers().size();
    if (size > 0) {
        if (size == 1 && settings.getSeedMembers().contains(gossipMember2SeedMember(getSelf()))) {
            return;
        }
        int index = (size == 1) ? 0 : random.nextInt(size);
        if (liveMembers.size() == 1) {
            sendGossip2Seed(buffer, settings.getSeedMembers(), index);
        } else {
            double prob = size / Double.valueOf(liveMembers.size());
            ;
            if (random.nextDouble() < prob) {
                sendGossip2Seed(buffer, settings.getSeedMembers(), index);
            }
        }
    }
}
 
开发者ID:monkeymq,项目名称:jgossip,代码行数:19,代码来源:GossipManager.java

示例6: modify

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Override
public FdfsClient modify(Buffer buffer, FdfsFileId fileId, long offset, Handler<AsyncResult<Void>> handler) {
	getTracker().setHandler(tracker -> {
		if (tracker.succeeded()) {
			tracker.result().getStoreStorage(fileId.group(), storage -> {
				if (storage.succeeded()) {
					storage.result().modify(buffer, fileId, offset, modify -> {
						handler.handle(modify);
					});
				} else {
					handler.handle(Future.failedFuture(storage.cause()));
				}
			});
		} else {
			handler.handle(Future.failedFuture(tracker.cause()));
		}
	});

	return this;
}
 
开发者ID:gengteng,项目名称:vertx-fastdfs-client,代码行数:21,代码来源:FdfsClientImpl.java

示例7: hello7Error

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Path("7error")
@GET
public CompletionStage<String> hello7Error(@Context Vertx vertx){
	io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	CompletableFuture<String> ret = new CompletableFuture<>();
	responseHandler.subscribe(body -> {
		System.err.println("Got body");
		
		ret.completeExceptionally(new MyException());
	});
	System.err.println("Created client");
	return ret;
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java

示例8: hello6

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Path("6")
@GET
public void hello6(@Suspended final AsyncResponse asyncResponse,
	      // Inject the Vertx instance
	      @Context Vertx vertx){
	io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	responseHandler.subscribe(body -> {
		System.err.println("Got body");
		asyncResponse.resume(Response.ok(body.body().toString()).build());
	});
	
	System.err.println("Created client");
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java

示例9: helloAsync

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Path("coroutines/1")
@GET
public Single<Response> helloAsync(@Context io.vertx.rxjava.core.Vertx rxVertx){
	return Fibers.fiber(() -> {
		System.err.println("Creating client");
		WebClientOptions options = new WebClientOptions();
		options.setSsl(true);
		options.setTrustAll(true);
		options.setVerifyHost(false);
		WebClient client = WebClient.create(rxVertx, options);
		Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
				"www.google.com", 
				"/robots.txt").rxSend();

		System.err.println("Got response");

		HttpResponse<io.vertx.rxjava.core.buffer.Buffer> httpResponse = Fibers.await(responseHandler);
		System.err.println("Got body");
		
		return Response.ok(httpResponse.body().toString()).build();
	});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:23,代码来源:MyResource.java

示例10: setBodyBuffer

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Test
public void setBodyBuffer() {
  Holder<Buffer> bodyHolder = new Holder<>();
  context = new MockUp<RoutingContext>() {
    @Mock
    HttpServerRequest request() {
      return vertxRequest;
    }

    @Mock
    void setBody(Buffer body) {
      bodyHolder.value = body;
    }
  }.getMockInstance();
  request = new VertxServerRequestToHttpServletRequest(context);

  Buffer bodyBuffer = Buffer.buffer();
  request.setBodyBuffer(bodyBuffer);

  Assert.assertSame(bodyBuffer, bodyHolder.value);
  Assert.assertSame(bodyBuffer, request.getBodyBuffer());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:TestVertxServerRequestToHttpServletRequest.java

示例11: testImplicitMode

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
public void testImplicitMode() {
    vertx = Vertx.vertx();
    WebClient client = WebClient.create(vertx);
    HttpRequest<Buffer> request = client.postAbs("http://admin:[email protected]:8080/oauth/authorize?response_type=token&scope=read%20write&client_id=myClientId&redirect_uri=http://example.com");
    request.putHeader("Authorization", getHeader());
    request.send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            //String location = response.getHeader("Location");
            String body = response.bodyAsString();
            System.out.println("Implicit Mode Get Token" + body + " status code" + response.statusCode() + " Location=");
        } else {
            System.out.println("Something went wrong " + ar.cause().getMessage());
        }
    });
}
 
开发者ID:openmg,项目名称:metagraph-auth,代码行数:17,代码来源:VertxWebTest.java

示例12: handle

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Override
public void handle(Buffer buff) {
  if (failed) {
    return;
  }
  uploadSize += buff.length();
  if (bodyLimit != -1 && uploadSize > bodyLimit) {
    failed = true;
    context.fail(Status.REQUEST_ENTITY_TOO_LARGE.getStatusCode());
  } else {
    // multipart requests will not end up in the request body
    // url encoded should also not, however jQuery by default
    // post in urlencoded even if the payload is something else
    if (!isMultipart /* && !isUrlEncoded */) {
      body.appendBuffer(buff);
    }
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:RestBodyHandler.java

示例13: hello8

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Path("8")
@GET
public Single<String> hello8(@Context io.vertx.rxjava.core.Vertx rxVertx){
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	System.err.println("Created client");
	return responseHandler.map(body -> {
		System.err.println("Got body");
		return body.body().toString();
	});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:20,代码来源:MyResource.java

示例14: transformBody

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
/**
 * Turns the JsonObject that came over the wire into a buffer object to be
 * used in the HTTP Post. Special twist: if configured the JSONObject is run
 * through a {{Mustache}} transformation, so the result can be anything
 * JSON, HTML, XML, PlainText, WebForm etc. Allows ultimate flexibility when
 * one knows Mustache
 *
 * @param Json
 *            Object with incoming payload
 * @return a Buffer object to be pasted
 */
private Buffer transformBody(final JsonObject body) {
	Buffer result = null;
	if (this.needsTransformation()) {
		final Mustache mustache = this.getMustache();
		final ByteArrayOutputStream out = new ByteArrayOutputStream();
		final PrintWriter pw = new PrintWriter(out);
		try {
			mustache.execute(pw, Utils.mappifyJsonObject(body)).flush();
			pw.close();
			result = Buffer.buffer(out.toByteArray());
		} catch (final IOException e) {
			this.logger.error(e);
			// Get back the unchanged body
			result = body.toBuffer();
		}
	} else {
		result = body.toBuffer();
	}
	return result;
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:32,代码来源:RestConsumer.java

示例15: addValue

import io.vertx.core.buffer.Buffer; //导入依赖的package包/类
@Override
public Tuple addValue(Object value) {
  if(value instanceof Boolean
    || value instanceof Number
    || value instanceof Character
    || value instanceof String
    || value instanceof JsonObject
    || value instanceof JsonArray
    || value instanceof Buffer
    || value instanceof LocalTime
    || value instanceof OffsetTime
    || value instanceof LocalDate
    || value instanceof LocalDateTime
    || value instanceof OffsetDateTime) {
    add(value);
  } else {
    add(null);
  }
  return this;
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:21,代码来源:ArrayTuple.java


注:本文中的io.vertx.core.buffer.Buffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。