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


Java ByteBufUtil.writeUtf8方法代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBufUtil.writeUtf8方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBufUtil.writeUtf8方法的具體用法?Java ByteBufUtil.writeUtf8怎麽用?Java ByteBufUtil.writeUtf8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.buffer.ByteBufUtil的用法示例。


在下文中一共展示了ByteBufUtil.writeUtf8方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encode

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
    byte[] pathBytes = fileId.pathBytes();
    int length = 2 * FDFS_LONG_LEN + FDFS_GROUP_LEN + pathBytes.length;
    byte cmd = FILE_DOWNLOAD;

    ByteBuf buf = alloc.buffer(length + FDFS_HEAD_LEN);
    buf.writeLong(length);
    buf.writeByte(cmd);
    buf.writeByte(ERRNO_OK);

    buf.writeLong(offset);
    buf.writeLong(size);
    writeFixLength(buf, fileId.group(), FDFS_GROUP_LEN);
    ByteBufUtil.writeUtf8(buf, fileId.path());
    return Collections.singletonList(buf);
}
 
開發者ID:rodbate,項目名稱:fastdfs-spring-boot,代碼行數:18,代碼來源:FileDownloadEncoder.java

示例2: encode

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
    byte[] pathBytes = fileId.pathBytes();
    int length = 2 * FDFS_LONG_LEN + FDFS_GROUP_LEN + pathBytes.length;
    byte cmd = FastdfsConstants.Commands.FILE_DOWNLOAD;

    ByteBuf buf = alloc.buffer(length + FDFS_HEAD_LEN);
    buf.writeLong(length);
    buf.writeByte(cmd);
    buf.writeByte(ERRNO_OK);

    buf.writeLong(offset);
    buf.writeLong(size);
    writeFixLength(buf, fileId.group(), FDFS_GROUP_LEN);
    ByteBufUtil.writeUtf8(buf, fileId.path());
    return Collections.singletonList(buf);
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:18,代碼來源:FileDownloadEncoder.java

示例3: onErrorWhenGettingNodeOne

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void onErrorWhenGettingNodeOne() {
    HttpClientResponse<ByteBuf> urlsResponse = mock(HttpClientResponse.class);
    ByteBuf byteBuf = (new PooledByteBufAllocator()).directBuffer();
    ByteBufUtil.writeUtf8(byteBuf, onePactSource);
    when(urlsResponse.getContent()).thenReturn(Observable.just(byteBuf));
    when(urlsResponse.getStatus()).thenReturn(HttpResponseStatus.OK);

    when(rxClient.submit(any(RxClient.ServerInfo.class), any(HttpClientRequest.class)))
            .thenReturn(Observable.just(urlsResponse), Observable.error(new RuntimeException()));

    TestSubscriber<Node> testSubscriber = new TestSubscriber<>();
    pactsAggregator.aggregateNodes().toBlocking().subscribe(testSubscriber);
    testSubscriber.assertError(RuntimeException.class);

    verify(publisher).publishEvent(any(SystemEvent.class));
}
 
開發者ID:ordina-jworks,項目名稱:microservices-dashboard-server,代碼行數:19,代碼來源:PactsAggregatorTest.java

示例4: call

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Override
public boolean call(WrappedRequest<S> req, WrappedResponse<S> res) throws IOException {
	File dest = new File(source, req.getPath());
	
	if (dest.exists()) {
		if (dest.isFile()) {
			serveFile(dest, res);
		} else {
			for (String i : INDICE) {
				File index = new File(dest, i);
				
				if (index.exists()) {
					serveFile(index, res);
					return true;
				}
			}

			res.setStatus(HttpResponseStatus.FORBIDDEN);
			ByteBufUtil.writeUtf8(res.getBuffer(), "FORBIDDEN");
		}
		
		return true;
	}
	
	return false;
}
 
開發者ID:lukasdietrich,項目名稱:lambdatra,代碼行數:27,代碼來源:StaticMiddleware.java

示例5: testFullRequestWithBody

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Test
public void testFullRequestWithBody() throws Exception {
  outputReceived = new CountDownLatch(1);
  String payload = "body";
  ByteBuf body = ByteBufUtil.writeUtf8(UnpooledByteBufAllocator.DEFAULT, payload);
  FullHttpRequest requestIn = new DefaultFullHttpRequest(HTTP_1_1, GET, "/", body);

  channel.writeInbound(requestIn);

  channel.runPendingTasks(); // blocks

  Uninterruptibles.awaitUninterruptibly(outputReceived);

  Request requestOut = requests.remove(0);

  assertTrue(requestOut != null);
  assertTrue(requestOut instanceof FullRequest);
  assertEquals("HTTP/1.1", requestOut.version());
  assertEquals(HttpMethod.GET, requestOut.method());
  assertEquals("/", requestOut.path());
  assertTrue(requestOut.hasBody());
  assertFalse(requestOut.body() == null);
  assertEquals(body, requestOut.body());
}
 
開發者ID:xjdr,項目名稱:xio,代碼行數:25,代碼來源:Http1ServerCodecUnitTest.java

示例6: testFullResponse

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Test
public void testFullResponse() throws Exception {
  outputReceived = new CountDownLatch(2);
  ByteBuf body = ByteBufUtil.writeUtf8(UnpooledByteBufAllocator.DEFAULT, "response");

  FullHttpRequest requestIn = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
  FullResponse responseIn = ResponseBuilders.newOk().body(body).build();

  channel.writeInbound(requestIn);
  channel.runPendingTasks(); // blocks
  channel.writeOutbound(responseIn);

  channel.runPendingTasks(); // blocks

  Uninterruptibles.awaitUninterruptibly(outputReceived);

  HttpResponse responseOut = (HttpResponse) responses.remove(0);

  assertTrue(responseOut != null);
  assertTrue(responseOut instanceof FullHttpResponse);
  assertEquals(HTTP_1_1, responseOut.protocolVersion());
  assertEquals(OK, responseOut.status());
  assertFalse(((FullHttpResponse) responseOut).content() == null);
  assertEquals(body, ((FullHttpResponse) responseOut).content());
}
 
開發者ID:xjdr,項目名稱:xio,代碼行數:26,代碼來源:Http1ServerCodecUnitTest.java

示例7: testFullRequestWithBody

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Test
public void testFullRequestWithBody() throws Exception {
  outputReceived = new CountDownLatch(1);
  ByteBuf body = ByteBufUtil.writeUtf8(UnpooledByteBufAllocator.DEFAULT, "body");
  FullRequest requestIn = RequestBuilders.newPost("/").body(body).build();

  channel.writeOutbound(requestIn);

  channel.runPendingTasks(); // blocks

  Uninterruptibles.awaitUninterruptibly(outputReceived);

  FullHttpRequest requestOut = (FullHttpRequest) requests.remove(0);

  assertTrue(requestOut != null);
  assertEquals(HTTP_1_1, requestOut.protocolVersion());
  assertEquals(HttpMethod.POST, requestOut.method());
  assertEquals("/", requestOut.uri());
  assertFalse(requestOut.content() == null);
  assertEquals(body, requestOut.content());
}
 
開發者ID:xjdr,項目名稱:xio,代碼行數:22,代碼來源:Http1ClientCodecUnitTest.java

示例8: testFullResponse

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Test
public void testFullResponse() throws Exception {
  outputReceived = new CountDownLatch(1);
  ByteBuf body = ByteBufUtil.writeUtf8(UnpooledByteBufAllocator.DEFAULT, "response");

  FullHttpResponse responseIn = new DefaultFullHttpResponse(HTTP_1_1, OK, body);

  channel.writeInbound(responseIn);

  channel.runPendingTasks(); // blocks

  Uninterruptibles.awaitUninterruptibly(outputReceived);

  Response responseOut = responses.remove(0);

  assertTrue(responseOut != null);
  assertTrue(responseOut instanceof FullResponse);
  assertEquals("HTTP/1.1", responseOut.version());
  assertEquals(OK, responseOut.status());
  assertTrue(responseOut.hasBody());
  assertFalse(responseOut.body() == null);
  assertEquals(body, responseOut.body());
}
 
開發者ID:xjdr,項目名稱:xio,代碼行數:24,代碼來源:Http1ClientCodecUnitTest.java

示例9: respondWithHttpError

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
private void respondWithHttpError(
    ChannelHandlerContext ctx, int streamId, int code, Status.Code statusCode, String msg) {
  Metadata metadata = new Metadata();
  metadata.put(InternalStatus.CODE_KEY, statusCode.toStatus());
  metadata.put(InternalStatus.MESSAGE_KEY, msg);
  byte[][] serialized = InternalMetadata.serialize(metadata);

  Http2Headers headers = new DefaultHttp2Headers(true, serialized.length / 2)
      .status("" + code)
      .set(CONTENT_TYPE_HEADER, "text/plain; encoding=utf-8");
  for (int i = 0; i < serialized.length; i += 2) {
    headers.add(new AsciiString(serialized[i], false), new AsciiString(serialized[i + 1], false));
  }
  encoder().writeHeaders(ctx, streamId, headers, 0, false, ctx.newPromise());
  ByteBuf msgBuf = ByteBufUtil.writeUtf8(ctx.alloc(), msg);
  encoder().writeData(ctx, streamId, msgBuf, 0, true, ctx.newPromise());
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:18,代碼來源:NettyServerHandler.java

示例10: writeString

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
public static void writeString(String str, ByteBuf cb)
{
    int writerIndex = cb.writerIndex();
    cb.writeShort(0);
    int lengthBytes = ByteBufUtil.writeUtf8(cb, str);
    cb.setShort(writerIndex, lengthBytes);
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:8,代碼來源:CBUtil.java

示例11: encode

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
    byte cmd = cmd();
    int length = FastdfsConstants.FDFS_GROUP_LEN + fileId.pathBytes().length;
    ByteBuf buf = alloc.buffer(length + FastdfsConstants.FDFS_HEAD_LEN);
    buf.writeLong(length);
    buf.writeByte(cmd);
    buf.writeByte(FastdfsConstants.ERRNO_OK);
    FastdfsUtils.writeFixLength(buf, fileId.group(), FastdfsConstants.FDFS_GROUP_LEN);
    ByteBufUtil.writeUtf8(buf, fileId.path());
    return Collections.singletonList(buf);
}
 
開發者ID:rodbate,項目名稱:fastdfs-spring-boot,代碼行數:13,代碼來源:FileIdOperationEncoder.java

示例12: writeUTF

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Override
public void writeUTF(String str) throws IOException {
    if (str.isEmpty()) {
        out.writeInt(0);
    } else {
        int startIdx = out.writerIndex();

        // Length placeholder.
        out.ensureWritable(Integer.BYTES).writerIndex(startIdx + Integer.BYTES);

        int len = ByteBufUtil.writeUtf8(out, str);

        out.setInt(startIdx, len);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:16,代碼來源:ByteBufDataWriter.java

示例13: encode

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
    byte cmd = cmd();
    int length = FDFS_GROUP_LEN + fileId.pathBytes().length;
    ByteBuf buf = alloc.buffer(length + FDFS_HEAD_LEN);
    buf.writeLong(length);
    buf.writeByte(cmd);
    buf.writeByte(ERRNO_OK);
    writeFixLength(buf, fileId.group(), FDFS_GROUP_LEN);
    ByteBufUtil.writeUtf8(buf, fileId.path());
    return Collections.singletonList(buf);
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:13,代碼來源:FileIdOperationEncoder.java

示例14: writeParameters

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
private static void writeParameters(List<CharSequence> parameters, ByteBuf out) {
  if (parameters.isEmpty()) {
    return;
  }

  out.writeByte(SP);

  if (parameters instanceof RandomAccess) {
    int sizeMinusOne = parameters.size() - 1;
    for (int i = 0; i < sizeMinusOne; i++) {
      ByteBufUtil.writeUtf8(out, parameters.get(i));
      out.writeByte(SP);
    }

    ByteBufUtil.writeUtf8(out, parameters.get(sizeMinusOne));

  } else {
    Iterator<CharSequence> params = parameters.iterator();
    while (true) {
      ByteBufUtil.writeUtf8(out, params.next());
      if (params.hasNext()) {
        out.writeByte(SP);
      } else {
        break;
      }
    }
  }
}
 
開發者ID:HubSpot,項目名稱:NioSmtpClient,代碼行數:29,代碼來源:Utf8SmtpRequestEncoder.java

示例15: shouldReturnOneNode

import io.netty.buffer.ByteBufUtil; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void shouldReturnOneNode() throws InterruptedException {

    HttpClientResponse<ByteBuf> urlsResponse = mock(HttpClientResponse.class);
    ByteBuf byteBuf = (new PooledByteBufAllocator()).directBuffer();
    ByteBufUtil.writeUtf8(byteBuf, onePactSource);
    when(urlsResponse.getContent()).thenReturn(Observable.just(byteBuf));
    when(urlsResponse.getStatus()).thenReturn(HttpResponseStatus.OK);

    HttpClientResponse<ByteBuf> pactTwoResponse = mock(HttpClientResponse.class);
    ByteBuf byteBuf3 = (new PooledByteBufAllocator()).directBuffer();
    ByteBufUtil.writeUtf8(byteBuf3, pactTwo);
    when(pactTwoResponse.getContent()).thenReturn(Observable.just(byteBuf3));
    when(pactTwoResponse.getStatus()).thenReturn(HttpResponseStatus.OK);

    when(rxClient.submit(any(RxClient.ServerInfo.class), any(HttpClientRequest.class)))
            .thenReturn(Observable.just(urlsResponse), Observable.just(pactTwoResponse));


    TestSubscriber<Node> testSubscriber = new TestSubscriber<>();
    pactsAggregator.aggregateNodes().toBlocking().subscribe(testSubscriber);
    testSubscriber.assertNoErrors();

    List<Node> nodes = testSubscriber.getOnNextEvents();
    assertThat(nodes).hasSize(1);

    assertThat(nodes.get(0).getId()).isEqualTo("consumer2");
    assertThat(nodes.get(0).getLane()).isEqualTo(0);
    assertThat(nodes.get(0).getLinkedToNodeIds()).contains("pn:provider2");
    assertThat(nodes.get(0).getDetails().get("url")).isEqualTo("http://someserver.be:7000/pacts/provider/provider2/consumer/consumer2/version/1.0.0");
    assertThat(nodes.get(0).getDetails().get("type")).isEqualTo(NodeTypes.UI_COMPONENT);
    assertThat(nodes.get(0).getDetails().get("status")).isEqualTo("UP");
}
 
開發者ID:ordina-jworks,項目名稱:microservices-dashboard-server,代碼行數:35,代碼來源:PactsAggregatorTest.java


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