本文整理汇总了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);
}
示例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);
}
示例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));
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
}
}
}
示例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");
}