當前位置: 首頁>>代碼示例>>Java>>正文


Java Buffer.buffer方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Stwissel,項目名稱:vertx-sfdc-platformevents,代碼行數:32,代碼來源:RestConsumer.java

示例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);
}
 
開發者ID:gengteng,項目名稱:vertx-fastdfs-client,代碼行數:24,代碼來源:FdfsProtocol.java

示例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]);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:9,代碼來源:TestVertxUtils.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:10,代碼來源:TestBodyBufferSupportImpl.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:11,代碼來源:TestBodyBufferSupportImpl.java

示例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;
}
 
開發者ID:noseka1,項目名稱:vertx-aws-lambda,代碼行數:10,代碼來源:HttpServerRequestImplTest.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:15,代碼來源:RestClientRequestImpl.java

示例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;
}
 
開發者ID:gengteng,項目名稱:vertx-fastdfs-client,代碼行數:32,代碼來源:FdfsStorageImpl.java

示例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;
}
 
開發者ID:monkeymq,項目名稱:jgossip,代碼行數:7,代碼來源:GossipManager.java

示例14: getBuffer

import io.vertx.core.buffer.Buffer; //導入方法依賴的package包/類
public Buffer getBuffer() {
  return Buffer.buffer(byteBuf);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:4,代碼來源:BufferOutputStream.java

示例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;
}
 
開發者ID:monkeymq,項目名稱:jgossip,代碼行數:7,代碼來源:GossipManager.java


注:本文中的io.vertx.core.buffer.Buffer.buffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。