当前位置: 首页>>代码示例>>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;未经允许,请勿转载。