本文整理匯總了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;
}