当前位置: 首页>>代码示例>>Java>>正文


Java EmbeddedChannel.writeOutbound方法代码示例

本文整理汇总了Java中io.netty.channel.embedded.EmbeddedChannel.writeOutbound方法的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedChannel.writeOutbound方法的具体用法?Java EmbeddedChannel.writeOutbound怎么用?Java EmbeddedChannel.writeOutbound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.embedded.EmbeddedChannel的用法示例。


在下文中一共展示了EmbeddedChannel.writeOutbound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
@Tag("fast")
public void encode() {
    IsoOnTcpMessage isoOnTcpMessage = new IsoOnTcpMessage(
        Unpooled.wrappedBuffer(new byte[]{(byte)0x01,(byte)0x02,(byte)0x03}));
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeOutbound(isoOnTcpMessage);
    channel.checkException();
    Object obj = channel.readOutbound();
    assertThat(obj).isInstanceOf(ByteBuf.class);
    ByteBuf byteBuf = (ByteBuf) obj;
    assertEquals(4 + 3, byteBuf.readableBytes(),
        "The TCP on ISO Header should add 4 bytes to the data sent");
    assertEquals(IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER, byteBuf.getByte(0));
    assertEquals(4 + 3, byteBuf.getShort(2),
        "The length value in the packet should reflect the size of the entire data being sent");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:18,代码来源:IsoOnTcpProtocolTest.java

示例2: testEmptyBufferBypass

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testEmptyBufferBypass() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel(new HttpResponseEncoder());

    // Test writing an empty buffer works when the encoder is at ST_INIT.
    channel.writeOutbound(Unpooled.EMPTY_BUFFER);
    ByteBuf buffer = (ByteBuf) channel.readOutbound();
    assertThat(buffer, is(sameInstance(Unpooled.EMPTY_BUFFER)));

    // Leave the ST_INIT state.
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    assertTrue(channel.writeOutbound(response));
    buffer = (ByteBuf) channel.readOutbound();
    assertEquals("HTTP/1.1 200 OK\r\n\r\n", buffer.toString(CharsetUtil.US_ASCII));
    buffer.release();

    // Test writing an empty buffer works when the encoder is not at ST_INIT.
    channel.writeOutbound(Unpooled.EMPTY_BUFFER);
    buffer = (ByteBuf) channel.readOutbound();
    assertThat(buffer, is(sameInstance(Unpooled.EMPTY_BUFFER)));

    assertFalse(channel.finish());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:24,代码来源:HttpResponseEncoderTest.java

示例3: testFullContent

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testFullContent() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new TestEncoder());
    ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));

    FullHttpResponse res = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(new byte[42]));
    res.headers().set(Names.CONTENT_LENGTH, 42);
    ch.writeOutbound(res);

    assertEncodedResponse(ch);
    HttpContent c = (HttpContent) ch.readOutbound();
    assertThat(c.content().readableBytes(), is(2));
    assertThat(c.content().toString(CharsetUtil.US_ASCII), is("42"));
    c.release();

    LastHttpContent last = (LastHttpContent) ch.readOutbound();
    assertThat(last.content().readableBytes(), is(0));
    last.release();

    assertThat(ch.readOutbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:23,代码来源:HttpContentEncoderTest.java

示例4: testEmptySplitContent

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * If the length of the content is unknown, {@link HttpContentEncoder} should not skip encoding the content
 * even if the actual length is turned out to be 0.
 */
@Test
public void testEmptySplitContent() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new TestEncoder());
    ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));

    ch.writeOutbound(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
    assertEncodedResponse(ch);

    ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
    HttpContent chunk = (HttpContent) ch.readOutbound();
    assertThat(chunk.content().toString(CharsetUtil.US_ASCII), is("0"));
    assertThat(chunk, is(instanceOf(HttpContent.class)));
    chunk.release();

    chunk = (HttpContent) ch.readOutbound();
    assertThat(chunk.content().isReadable(), is(false));
    assertThat(chunk, is(instanceOf(LastHttpContent.class)));
    chunk.release();

    assertThat(ch.readOutbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:HttpContentEncoderTest.java

示例5: testEmptyFullContent

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * If the length of the content is 0 for sure, {@link HttpContentEncoder} should skip encoding.
 */
@Test
public void testEmptyFullContent() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new TestEncoder());
    ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));

    FullHttpResponse res = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER);
    ch.writeOutbound(res);

    Object o = ch.readOutbound();
    assertThat(o, is(instanceOf(FullHttpResponse.class)));

    res = (FullHttpResponse) o;
    assertThat(res.headers().get(Names.TRANSFER_ENCODING), is(nullValue()));

    // Content encoding shouldn't be modified.
    assertThat(res.headers().get(Names.CONTENT_ENCODING), is(nullValue()));
    assertThat(res.content().readableBytes(), is(0));
    assertThat(res.content().toString(CharsetUtil.US_ASCII), is(""));
    res.release();

    assertThat(ch.readOutbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:27,代码来源:HttpContentEncoderTest.java

示例6: testTextWithLen

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
private void testTextWithLen(EmbeddedChannel outChannel, EmbeddedChannel inChannel, int testDataLength) {
    String testStr = strTestData.substring(0, testDataLength);
    outChannel.writeOutbound(new TextWebSocketFrame(testStr));

    // Transfer encoded data into decoder
    // Loop because there might be multiple frames (gathering write)
    while (true) {
        ByteBuf encoded = (ByteBuf) outChannel.readOutbound();
        if (encoded != null) {
            inChannel.writeInbound(encoded);
        } else {
            break;
        }
    }

    Object decoded = inChannel.readInbound();
    Assert.assertNotNull(decoded);
    Assert.assertTrue(decoded instanceof TextWebSocketFrame);
    TextWebSocketFrame txt = (TextWebSocketFrame) decoded;
    Assert.assertEquals(txt.text(), testStr);
    txt.release();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:23,代码来源:WebSocket08EncoderDecoderTest.java

示例7: testNonByteBufPassthrough

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testNonByteBufPassthrough() throws Exception {
    SSLEngine engine = SSLContext.getDefault().createSSLEngine();
    engine.setUseClientMode(false);

    EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(engine));

    Object msg1 = new Object();
    ch.writeOutbound(msg1);
    assertThat(ch.readOutbound(), is(sameInstance(msg1)));

    Object msg2 = new Object();
    ch.writeInbound(msg2);
    assertThat(ch.readInbound(), is(sameInstance(msg2)));

    ch.finish();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:18,代码来源:SslHandlerTest.java

示例8: testEncoder

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testEncoder() {
    String writeData = "안녕하세요";
    ByteBuf request = Unpooled.wrappedBuffer(writeData.getBytes());

    Base64Encoder encoder = new Base64Encoder();
    EmbeddedChannel embeddedChannel = new EmbeddedChannel(encoder);

    embeddedChannel.writeOutbound(request);
    ByteBuf response = (ByteBuf) embeddedChannel.readOutbound();

    String expect = "7JWI64WV7ZWY7IS47JqU";
    assertEquals(expect, response.toString(Charset.defaultCharset()));

    embeddedChannel.finish();
}
 
开发者ID:krisjey,项目名称:netty.book.kor,代码行数:17,代码来源:Base64EncoderTest.java

示例9: testEmptyFullContent

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * If the length of the content is 0 for sure, {@link HttpContentEncoder} should skip encoding.
 */
@Test
public void testEmptyFullContent() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpContentCompressor());
    ch.writeInbound(newRequest());

    FullHttpResponse res = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER);
    ch.writeOutbound(res);

    Object o = ch.readOutbound();
    assertThat(o, is(instanceOf(FullHttpResponse.class)));

    res = (FullHttpResponse) o;
    assertThat(res.headers().get(Names.TRANSFER_ENCODING), is(nullValue()));

    // Content encoding shouldn't be modified.
    assertThat(res.headers().get(Names.CONTENT_ENCODING), is(nullValue()));
    assertThat(res.content().readableBytes(), is(0));
    assertThat(res.content().toString(CharsetUtil.US_ASCII), is(""));
    res.release();

    assertThat(ch.readOutbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:27,代码来源:HttpContentCompressorTest.java

示例10: testPrependLengthInLittleEndian

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testPrependLengthInLittleEndian() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(ByteOrder.LITTLE_ENDIAN, 4, 0, false));
    ch.writeOutbound(msg);
    ByteBuf buf = (ByteBuf) ch.readOutbound();
    assertEquals(5, buf.readableBytes());
    byte[] writtenBytes = new byte[buf.readableBytes()];
    buf.getBytes(0, writtenBytes);
    assertEquals(1, writtenBytes[0]);
    assertEquals(0, writtenBytes[1]);
    assertEquals(0, writtenBytes[2]);
    assertEquals(0, writtenBytes[3]);
    assertEquals('A', writtenBytes[4]);
    buf.release();
    assertFalse("The channel must have been completely read", ch.finish());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:LengthFieldPrependerTest.java

示例11: makeEntitySpawnAdjustment

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
public static void makeEntitySpawnAdjustment(Entity entity, EntityPlayerMP player, int serverX, int serverY, int serverZ)
{
    EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
    embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER);
    embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
    embeddedChannel.writeOutbound(new FMLMessage.EntityAdjustMessage(entity, serverX, serverY, serverZ));
}
 
开发者ID:SchrodingersSpy,项目名称:TRHS_Club_Mod_2016,代码行数:8,代码来源:FMLNetworkHandler.java

示例12: encodeTest

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void encodeTest() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel(new RconEncoder());
    ByteBuf expected = Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary("00000000030000006d7920766f696365206973206d792070617373706f72740000"));
    try {
        channel.writeOutbound(new RconMessage(0, 3, "my voice is my passport"));
        ByteBuf buf = (ByteBuf) channel.readOutbound();
        Assert.assertEquals("Read message is invalid.", expected, buf);
    } finally {
        expected.release();
        channel.close();
    }
}
 
开发者ID:voxelwind,项目名称:voxelwind,代码行数:14,代码来源:RconEncodeDecodeTest.java

示例13: testAdjustedLengthLessThanZero

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testAdjustedLengthLessThanZero() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -2));
    try {
        ch.writeOutbound(msg);
        fail(EncoderException.class.getSimpleName() + " must be raised.");
    } catch (EncoderException e) {
        // Expected
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:11,代码来源:LengthFieldPrependerTest.java

示例14: testSplitContent

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testSplitContent() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new TestEncoder());
    ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));

    ch.writeOutbound(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
    ch.writeOutbound(new DefaultHttpContent(Unpooled.wrappedBuffer(new byte[3])));
    ch.writeOutbound(new DefaultHttpContent(Unpooled.wrappedBuffer(new byte[2])));
    ch.writeOutbound(new DefaultLastHttpContent(Unpooled.wrappedBuffer(new byte[1])));

    assertEncodedResponse(ch);

    HttpContent chunk;
    chunk = (HttpContent) ch.readOutbound();
    assertThat(chunk.content().toString(CharsetUtil.US_ASCII), is("3"));
    chunk.release();

    chunk = (HttpContent) ch.readOutbound();
    assertThat(chunk.content().toString(CharsetUtil.US_ASCII), is("2"));
    chunk.release();

    chunk = (HttpContent) ch.readOutbound();
    assertThat(chunk.content().toString(CharsetUtil.US_ASCII), is("1"));
    chunk.release();

    chunk = (HttpContent) ch.readOutbound();
    assertThat(chunk.content().isReadable(), is(false));
    assertThat(chunk, is(instanceOf(LastHttpContent.class)));
    chunk.release();

    assertThat(ch.readOutbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:33,代码来源:HttpContentEncoderTest.java

示例15: testPrependAdjustedLength

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testPrependAdjustedLength() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -1));
    ch.writeOutbound(msg);
    final ByteBuf buf = (ByteBuf) ch.readOutbound();
    assertThat(buf, is(wrappedBuffer(new byte[]{0, 0, 0, 0, 'A'})));
    buf.release();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:9,代码来源:LengthFieldPrependerTest.java


注:本文中的io.netty.channel.embedded.EmbeddedChannel.writeOutbound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。