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


Java EmbeddedChannel.readInbound方法代码示例

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


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

示例1: decode

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * Happy path test.
 */
@Test
@Tag("fast")
public void decode() {
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
        (byte)0x00,(byte)0x00,(byte)0x0D,
        (byte)0x01,(byte)0x02,(byte)0x03,(byte)0x04,(byte)0x05,(byte)0x06,(byte)0x07,(byte)0x08,(byte)0x09}));
    channel.checkException();
    Object obj = channel.readInbound();
    assertThat(obj).isInstanceOf(IsoOnTcpMessage.class);
    IsoOnTcpMessage isoOnTcpMessage = (IsoOnTcpMessage) obj;
    assertNotNull(isoOnTcpMessage.getUserData());
    assertEquals(9, isoOnTcpMessage.getUserData().readableBytes());
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:18,代码来源:IsoOnTcpProtocolTest.java

示例2: addDecoderReplaysLastHttp

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void addDecoderReplaysLastHttp() throws Exception {
	ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
	EmbeddedChannel channel = new EmbeddedChannel();
	HttpClientOperations ops = new HttpClientOperations(channel,
			(response, request) -> null, handler);

	ops.addHandler(new JsonObjectDecoder());
	channel.writeInbound(new DefaultLastHttpContent(buf));

	assertThat(channel.pipeline().names().iterator().next(), is("JsonObjectDecoder$extractor"));

	Object content = channel.readInbound();
	assertThat(content, instanceOf(ByteBuf.class));
	((ByteBuf) content).release();

	content = channel.readInbound();
	assertThat(content, instanceOf(LastHttpContent.class));
	((LastHttpContent) content).release();

	assertThat(channel.readInbound(), nullValue());
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:23,代码来源:HttpClientOperationsTest.java

示例3: addNamedDecoderReplaysLastHttp

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void addNamedDecoderReplaysLastHttp() throws Exception {
	ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
	EmbeddedChannel channel = new EmbeddedChannel();
	HttpClientOperations ops = new HttpClientOperations(channel,
			(response, request) -> null, handler);

	ops.addHandler("json", new JsonObjectDecoder());
	channel.writeInbound(new DefaultLastHttpContent(buf));

	assertThat(channel.pipeline().names().iterator().next(), is("json$extractor"));

	Object content = channel.readInbound();
	assertThat(content, instanceOf(ByteBuf.class));
	((ByteBuf) content).release();

	content = channel.readInbound();
	assertThat(content, instanceOf(LastHttpContent.class));
	((LastHttpContent) content).release();

	assertThat(channel.readInbound(), nullValue());
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:23,代码来源:HttpClientOperationsTest.java

示例4: addEncoderReplaysLastHttp

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void addEncoderReplaysLastHttp() throws Exception {
	ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
	EmbeddedChannel channel = new EmbeddedChannel();
	HttpClientOperations ops = new HttpClientOperations(channel,
			(response, request) -> null, handler);

	ops.addHandler(new JsonObjectDecoder());
	channel.writeInbound(new DefaultLastHttpContent(buf));

	assertThat(channel.pipeline().names().iterator().next(), is("JsonObjectDecoder$extractor"));

	Object content = channel.readInbound();
	assertThat(content, instanceOf(ByteBuf.class));
	((ByteBuf) content).release();

	content = channel.readInbound();
	assertThat(content, instanceOf(LastHttpContent.class));
	((LastHttpContent) content).release();

	assertThat(channel.readInbound(), nullValue());
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:23,代码来源:HttpClientOperationsTest.java

示例5: addNamedEncoderReplaysLastHttp

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void addNamedEncoderReplaysLastHttp() throws Exception {
	ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
	EmbeddedChannel channel = new EmbeddedChannel();
	HttpClientOperations ops = new HttpClientOperations(channel,
			(response, request) -> null, handler);

	ops.addHandler("json", new JsonObjectDecoder());
	channel.writeInbound(new DefaultLastHttpContent(buf));

	assertThat(channel.pipeline().names().iterator().next(), is("json$extractor"));

	Object content = channel.readInbound();
	assertThat(content, instanceOf(ByteBuf.class));
	((ByteBuf) content).release();

	content = channel.readInbound();
	assertThat(content, instanceOf(LastHttpContent.class));
	((LastHttpContent) content).release();

	assertThat(channel.readInbound(), nullValue());
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:23,代码来源:HttpClientOperationsTest.java

示例6: testDecoder

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testDecoder() {
    ByteBuf buf = Unpooled.buffer();
    buf.writeBytes(VALUE.getBytes());
    ByteBuf input = buf.duplicate();
    AddressedEnvelope<Object, InetSocketAddress> addressedEnvelop =
            new DefaultAddressedEnvelope<Object, InetSocketAddress>(input, new InetSocketAddress(8888));
    EmbeddedChannel channel = new EmbeddedChannel(ChannelHandlerFactories.newByteArrayDecoder("udp").newChannelHandler());
    Assert.assertTrue(channel.writeInbound(addressedEnvelop));
    Assert.assertTrue(channel.finish());
    AddressedEnvelope<Object, InetSocketAddress> result = (AddressedEnvelope) channel.readInbound();
    Assert.assertEquals(result.recipient().getPort(), addressedEnvelop.recipient().getPort());
    Assert.assertTrue(result.content() instanceof byte[]);
    Assert.assertEquals(VALUE, new String((byte[]) result.content()));
    Assert.assertNull(channel.readInbound());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:DatagramPacketByteArrayCodecTest.java

示例7: testPrematureClosureWithChunkedEncoding1

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testPrematureClosureWithChunkedEncoding1() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
    ch.writeInbound(
            Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n", CharsetUtil.US_ASCII));

    // Read the response headers.
    HttpResponse res = (HttpResponse) ch.readInbound();
    assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
    assertThat(res.getStatus(), is(HttpResponseStatus.OK));
    assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));
    assertThat(ch.readInbound(), is(nullValue()));

    // Close the connection without sending anything.
    ch.finish();
    // The decoder should not generate the last chunk because it's closed prematurely.
    assertThat(ch.readInbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:19,代码来源:HttpResponseDecoderTest.java

示例8: testSocksCmdRequestDecoderWithDifferentParams

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
private static void testSocksCmdRequestDecoderWithDifferentParams(SocksCmdType cmdType,
                                                                  SocksAddressType addressType,
                                                                  String host,
                                                                  int port) {
    logger.debug("Testing cmdType: " + cmdType + " addressType: " + addressType + " host: " + host +
            " port: " + port);
    SocksCmdRequest msg = new SocksCmdRequest(cmdType, addressType, host, port);
    SocksCmdRequestDecoder decoder = new SocksCmdRequestDecoder();
    EmbeddedChannel embedder = new EmbeddedChannel(decoder);
    SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
    if (msg.addressType() == SocksAddressType.UNKNOWN) {
        assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
    } else {
        msg = (SocksCmdRequest) embedder.readInbound();
        assertSame(msg.cmdType(), cmdType);
        assertSame(msg.addressType(), addressType);
        assertEquals(msg.host(), host);
        assertEquals(msg.port(), port);
    }
    assertNull(embedder.readInbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:22,代码来源:SocksCmdRequestDecoderTest.java

示例9: testLastResponseWithoutContentLengthHeader

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testLastResponseWithoutContentLengthHeader() {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
    ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\n\r\n", CharsetUtil.US_ASCII));

    HttpResponse res = (HttpResponse) ch.readInbound();
    assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
    assertThat(res.getStatus(), is(HttpResponseStatus.OK));
    assertThat(ch.readInbound(), is(nullValue()));

    ch.writeInbound(Unpooled.wrappedBuffer(new byte[1024]));
    HttpContent content = (HttpContent) ch.readInbound();
    assertThat(content.content().readableBytes(), is(1024));
    content.release();

    assertThat(ch.finish(), is(true));

    LastHttpContent lastContent = (LastHttpContent) ch.readInbound();
    assertThat(lastContent.content().isReadable(), is(false));
    lastContent.release();

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

示例10: testClosureWithoutContentLength1

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testClosureWithoutContentLength1() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
    ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\n\r\n", CharsetUtil.US_ASCII));

    // Read the response headers.
    HttpResponse res = (HttpResponse) ch.readInbound();
    assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
    assertThat(res.getStatus(), is(HttpResponseStatus.OK));
    assertThat(ch.readInbound(), is(nullValue()));

    // Close the connection without sending anything.
    assertTrue(ch.finish());

    // The decoder should still produce the last content.
    LastHttpContent content = (LastHttpContent) ch.readInbound();
    assertThat(content.content().isReadable(), is(false));
    content.release();

    // But nothing more.
    assertThat(ch.readInbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:23,代码来源:HttpResponseDecoderTest.java

示例11: testSimpleUnmarshalling

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testSimpleUnmarshalling() throws IOException {
    MarshallerFactory marshallerFactory = createMarshallerFactory();
    MarshallingConfiguration configuration = createMarshallingConfig();

    EmbeddedChannel ch = new EmbeddedChannel(createDecoder(Integer.MAX_VALUE));

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
    marshaller.start(Marshalling.createByteOutput(bout));
    marshaller.writeObject(testObject);
    marshaller.finish();
    marshaller.close();

    byte[] testBytes = bout.toByteArray();

    ch.writeInbound(input(testBytes));
    assertTrue(ch.finish());

    String unmarshalled = (String) ch.readInbound();

    assertEquals(testObject, unmarshalled);

    assertNull(ch.readInbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:AbstractCompatibleMarshallingDecoderTest.java

示例12: 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

示例13: collect10NetflowV5MessagesFromChannel

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@NotNull
private List<Record> collect10NetflowV5MessagesFromChannel(EmbeddedChannel ch, int packetLength) {
  List<Record> records = new LinkedList<>();
  for (int i=0; i<10; i++) {
    Object object = ch.readInbound();
    assertNotNull(object);
    assertThat(object, is(instanceOf(NetflowV5Message.class)));
    NetflowV5Message msg = (NetflowV5Message) object;
    // fix packet length for test; it passes in MAX_LENGTH by default
    msg.setLength(packetLength);
    Record record = RecordCreator.create();
    msg.populateRecord(record);
    records.add(record);
  }
  return records;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:17,代码来源:TestNetflowDecoder.java

示例14: decodeWayTooShort

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * If the available amount of data is so small we can't even find out how big
 * the entire package should be, nothing should be read.
 */
@Test
@Tag("fast")
public void decodeWayTooShort() {
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
        (byte)0x00,(byte)0x00,(byte)0x0D}));
    channel.checkException();
    Object obj = channel.readInbound();
    assertNull(obj, "Nothing should have been decoded");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:15,代码来源:IsoOnTcpProtocolTest.java

示例15: decodeTooShort

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * If the available amount of data is smaller than what the packet size says
 * it should be, nothing should be read.
 */
@Test
@Tag("fast")
public void decodeTooShort() {
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
        (byte)0x00,(byte)0x00,(byte)0x0D,
        (byte)0x01,(byte)0x02,(byte)0x03,(byte)0x04,(byte)0x05,(byte)0x06,(byte)0x07,(byte)0x08}));
    channel.checkException();
    Object obj = channel.readInbound();
    assertNull(obj, "Nothing should have been decoded");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:16,代码来源:IsoOnTcpProtocolTest.java


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