本文整理匯總了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());
}
});
}
示例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");
}
}
示例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));
}
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
示例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;
}
示例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");
}
示例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();
});
}
示例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());
}
});
}
示例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);
}
}
}
示例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();
});
}
示例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;
}
示例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;
}