本文整理汇总了Java中io.vertx.core.buffer.Buffer.buffer方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.buffer方法的具体用法?Java Buffer.buffer怎么用?Java Buffer.buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
示例2: 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;
}
示例3: packMetaData
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
/**
* 封装metadata为Buffer。
*
* @param meta meta
* @param charset charset
* @return Buffer
*/
public static Buffer packMetaData(JsonObject meta, String charset) {
StringBuilder builder = new StringBuilder();
meta.forEach(pair -> {
builder.append(pair.getKey());
builder.append(FDFS_FIELD_SEPERATOR);
builder.append(pair.getValue());
builder.append(FDFS_RECORD_SEPERATOR);
});
if (builder.length() > 0) {
builder.deleteCharAt(builder.length() - 1);
}
return Buffer.buffer(builder.toString(), charset);
}
示例4: testgetBytesFastBuffer
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
@Test
public void testgetBytesFastBuffer() {
Buffer buffer = Buffer.buffer();
buffer.appendByte((byte) 1);
byte[] result = VertxUtils.getBytesFast(buffer);
Assert.assertEquals(1, result[0]);
}
示例5: testGetBodyBuffer
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
@Test
public void testGetBodyBuffer() {
Assert.assertNull(impl.getBodyBuffer());
Buffer bodyBuffer = Buffer.buffer();
impl.setBodyBuffer(bodyBuffer);
Assert.assertSame(bodyBuffer, impl.getBodyBuffer());
}
示例6: testGetBodyBytes
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
@Test
public void testGetBodyBytes() {
Assert.assertNull(impl.getBodyBytes());
byte[] bytes = new byte[] {1, 2, 3};
Buffer bodyBuffer = Buffer.buffer(bytes);
impl.setBodyBuffer(bodyBuffer);
Assert.assertArrayEquals(bytes, impl.getBodyBytes());
}
示例7: setBodyBuffer
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
@Test
public void setBodyBuffer() {
Buffer bodyBuffer = Buffer.buffer();
bodyBuffer.appendString("abc");
requestEx.setBodyBuffer(bodyBuffer);
Assert.assertSame(bodyBuffer, requestEx.getBodyBuffer());
Assert.assertArrayEquals("abc".getBytes(), Arrays.copyOf(requestEx.getBodyBytes(), requestEx.getBodyBytesLength()));
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:10,代码来源:TestStandardHttpServletRequestEx.java
示例8: inputStreamToBuffer
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private static Buffer inputStreamToBuffer(InputStream input) throws IOException {
byte[] data = new byte[1024];
Buffer buffer = Buffer.buffer();
while (((input.read(data, 0, data.length))) != -1) {
buffer.appendBytes(data);
}
return buffer;
}
示例9: getBodyBytes
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
@Test
public void getBodyBytes() {
Buffer bodyBuffer = Buffer.buffer();
bodyBuffer.appendString("abc");
responseEx.setBodyBuffer(bodyBuffer);
Assert.assertEquals("abc", new String(responseEx.getBodyBytes(), 0, responseEx.getBodyBytesLength()));
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:TestStandardHttpServletResponseEx.java
示例10: getBodyBytesLength
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
@Test
public void getBodyBytesLength() {
Buffer bodyBuffer = Buffer.buffer();
bodyBuffer.appendString("abc");
responseEx.setBodyBuffer(bodyBuffer);
Assert.assertEquals(3, responseEx.getBodyBytesLength());
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:TestStandardHttpServletResponseEx.java
示例11: fileBoundaryInfo
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
protected Buffer fileBoundaryInfo(String boundary, String name, Part part) {
Buffer buffer = Buffer.buffer();
buffer.appendString("\r\n");
buffer.appendString("--" + boundary + "\r\n");
buffer.appendString("Content-Disposition: form-data; name=\"")
.appendString(name)
.appendString("\"; filename=\"")
.appendString(part.getSubmittedFileName() != null ? part.getSubmittedFileName() : "null")
.appendString("\"\r\n");
buffer.appendString("Content-Type: ").appendString(part.getContentType()).appendString("\r\n");
buffer.appendString("Content-Transfer-Encoding: binary\r\n");
buffer.appendString("\r\n");
return buffer;
}
示例12: uploadFile
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
private Future<FdfsFileId> uploadFile(byte command, String fileFullPathName, String ext) {
Buffer extBuffer = Buffer.buffer(ext, options.getCharset());
if (extBuffer.length() > FdfsProtocol.FDFS_FILE_EXT_NAME_MAX_LEN) {
return Future.failedFuture("ext is too long ( greater than " + FdfsProtocol.FDFS_FILE_EXT_NAME_MAX_LEN + ")");
}
Future<FdfsFileId> futureFileId = Future.future();
LocalFile.readFile(vertx.fileSystem(), fileFullPathName).setHandler(ar -> {
if (ar.succeeded()) {
LocalFile localFile = ar.result();
uploadFile(command, localFile.getFile(), localFile.getSize(), ext).setHandler(upload -> {
localFile.closeFile();
if (upload.succeeded()) {
futureFileId.complete(upload.result());
} else {
futureFileId.fail(upload.cause());
}
});
} else {
futureFileId.fail(ar.cause());
}
});
return futureFileId;
}
示例13: encodeAckMessage
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
public Buffer encodeAckMessage(AckMessage ackMessage) {
Buffer buffer = Buffer.buffer();
JsonObject ackJson = JsonObject.mapFrom(ackMessage);
buffer.appendString(GossipMessageFactory.getInstance().makeMessage(MessageType.ACK_MESSAGE, ackJson.encode(), getCluster(), getSelf().ipAndPort()).encode());
return buffer;
}
示例14: getBuffer
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
public Buffer getBuffer() {
return Buffer.buffer(byteBuf);
}
示例15: encodeAck2Message
import io.vertx.core.buffer.Buffer; //导入方法依赖的package包/类
public Buffer encodeAck2Message(Ack2Message ack2Message) {
Buffer buffer = Buffer.buffer();
JsonObject ack2Json = JsonObject.mapFrom(ack2Message);
buffer.appendString(GossipMessageFactory.getInstance().makeMessage(MessageType.ACK2_MESSAGE, ack2Json.encode(), getCluster(), getSelf().ipAndPort()).encode());
return buffer;
}