當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。