• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EmptyByteBuf类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.buffer.EmptyByteBuf的典型用法代码示例。如果您正苦于以下问题:Java EmptyByteBuf类的具体用法?Java EmptyByteBuf怎么用?Java EmptyByteBuf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EmptyByteBuf类属于io.netty.buffer包,在下文中一共展示了EmptyByteBuf类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decode

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	try {
		//LibraLog.info("decode is bytebuf in is :" + JsonUtil.ObjectToJsonString(in.array()));
		// 空的buf
		if (in instanceof EmptyByteBuf || in.readableBytes() < 0) {
			return;
		}
		short length = in.readShort();
		if (length != in.readableBytes()) {
			return;
		}
		// 反序列化
		LibraMessage message = LibraMessage.decode(in);
		if (message == null) {
			return;
		}
		out.add(message);
	} catch (Exception e) {
		e.printStackTrace();
		return;
	}
}
 
开发者ID:inspingcc,项目名称:LibraSock,代码行数:24,代码来源:LibraDecoder.java


示例2: decode

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Override
protected void decode( ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list ) throws Exception {
    if( byteBuf instanceof EmptyByteBuf ) {
        System.out.println( "Got empty byte buf for " + channelHandlerContext.name() );
        return;
    }

    ConnectionHandler connectionHandler = (ConnectionHandler) channelHandlerContext.pipeline().get( "connectionHandler" );
    int messageId = Message.readVarInt( byteBuf );
    Message message = connectionManager.getRegistry( connectionHandler ).createMessageFromId( messageId );
    if( message == null ) {

        System.out.println( "Cannot find message id " + messageId );
        while ( byteBuf.readableBytes() > 0 ){
            byteBuf.readByte();
        }
        return;
    }
    message.read( byteBuf );

    list.add( message );
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:23,代码来源:MessageDecoder.java


示例3: convertContentChunksToRawString_and_convertContentChunksToRawBytes_works_with_EmptyByteBuf_chunks

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Test
public void convertContentChunksToRawString_and_convertContentChunksToRawBytes_works_with_EmptyByteBuf_chunks() throws IOException {
    // given
    Charset contentCharset = CharsetUtil.UTF_8;
    String chunk1Content = UUID.randomUUID().toString();
    String chunk2Content = UUID.randomUUID().toString();
    byte[] chunk1Bytes = chunk1Content.getBytes(contentCharset);
    byte[] chunk2Bytes = chunk2Content.getBytes(contentCharset);
    ByteBuf chunk1ByteBuf = Unpooled.copiedBuffer(chunk1Bytes);
    ByteBuf chunk2ByteBuf = Unpooled.copiedBuffer(chunk2Bytes);
    Collection<HttpContent> chunkCollection = Arrays.asList(
            new DefaultHttpContent(chunk1ByteBuf),
            new DefaultHttpContent(new EmptyByteBuf(ByteBufAllocator.DEFAULT)),
            new DefaultHttpContent(chunk2ByteBuf),
            new DefaultHttpContent(new EmptyByteBuf(ByteBufAllocator.DEFAULT))
    );

    // when
    String resultString = HttpUtils.convertContentChunksToRawString(contentCharset, chunkCollection);
    byte[] resultBytes = HttpUtils.convertContentChunksToRawBytes(chunkCollection);

    // then
    String expectedResultString = chunk1Content + chunk2Content;
    assertThat(resultString, is(expectedResultString));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(chunk1Bytes);
    baos.write(chunk2Bytes);
    assertThat(resultBytes, is(baos.toByteArray()));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:30,代码来源:HttpUtilsTest.java


示例4: convertContentChunksToRawBytes_returns_null_if_total_bytes_is_zero

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Test
public void convertContentChunksToRawBytes_returns_null_if_total_bytes_is_zero() {
    // given
    Collection<HttpContent> chunkCollection = Arrays.asList(new DefaultHttpContent(new EmptyByteBuf(ByteBufAllocator.DEFAULT)),
            new DefaultHttpContent(new EmptyByteBuf(ByteBufAllocator.DEFAULT)));

    // when
    byte[] resultBytes = HttpUtils.convertContentChunksToRawBytes(chunkCollection);

    // then
    assertThat(resultBytes, nullValue());
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:13,代码来源:HttpUtilsTest.java


示例5: channelRead

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Override
final public void channelRead(ChannelHandlerContext ctx, Object msg)
		throws Exception {
	if (msg == null || msg == Unpooled.EMPTY_BUFFER || msg instanceof EmptyByteBuf) {
		return;
	}
	try {
		ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
		if (ops != null) {
			ops.onInboundNext(ctx, msg);
		}
		else {
			if (log.isDebugEnabled()) {
				String loggingMsg = msg.toString();
				if (msg instanceof HttpResponse) {
					DecoderResult decoderResult = ((HttpResponse) msg).decoderResult();
					if (decoderResult.isFailure()) {
						log.debug("Decoding failed: " + msg + " : ", decoderResult.cause());
					}
				}
				if (msg instanceof ByteBufHolder) {
					loggingMsg = ((ByteBufHolder) msg).content()
					                                  .toString(Charset.defaultCharset());
				}
				log.debug("{} No ChannelOperation attached. Dropping: {}", ctx
						.channel().toString(), loggingMsg);
			}
			ReferenceCountUtil.release(msg);
		}
	}
	catch (Throwable err) {
		Exceptions.throwIfFatal(err);
		exceptionCaught(ctx, err);
		ReferenceCountUtil.safeRelease(msg);
	}
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:37,代码来源:ChannelOperationsHandler.java


示例6: decode

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Override
protected void decode( ChannelHandlerContext channelHandlerContext, ByteBuf buf, List<Object> objects ) throws Exception {
    if ( buf instanceof EmptyByteBuf ) {
        // The Channel has disconnected and this is the last message we got. R.I.P. connection
        return;
    }

    byte packetId = buf.readByte();
    switch ( packetId ) {
        case 1:
            WrappedMCPEPacket wrappedMCPEPacket = new WrappedMCPEPacket();
            wrappedMCPEPacket.read( buf );
            objects.add( wrappedMCPEPacket );
            break;
        case 2:
            UpdatePingPacket updatePingPacket = new UpdatePingPacket();
            updatePingPacket.read( buf );
            objects.add( updatePingPacket );
            break;
        case 3:
            SendPlayerToServerPacket sendPlayerToServerPacket = new SendPlayerToServerPacket();
            sendPlayerToServerPacket.read( buf );
            objects.add( sendPlayerToServerPacket );
            break;
        default:
            break;
    }
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:29,代码来源:Decoder.java


示例7: sendInternal

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
/**
 * Sends a message either on behalf of the client or on behalf of the broker (Will Messages)
 * @param messageId
 * @param topic
 * @param qos
 * @param payload
 * @param retain
 * @param internal if true means on behalf of the broker (skips authorisation) and does not return ack.
 * @throws Exception
 */
void sendInternal(int messageId, String topic, int qos, ByteBuf payload, boolean retain, boolean internal) throws Exception {
   synchronized (lock) {
      Message serverMessage = MQTTUtil.createServerMessageFromByteBuf(session, topic, retain, qos, payload);

      if (qos > 0) {
         serverMessage.setDurable(MQTTUtil.DURABLE_MESSAGES);
      }

      if (qos < 2 || !state.getPubRec().contains(messageId)) {
         if (qos == 2 && !internal)
            state.getPubRec().add(messageId);

         Transaction tx = session.getServerSession().newTransaction();
         try {
            if (internal) {
               session.getServer().getPostOffice().route(serverMessage, tx, true);
            } else {
               session.getServerSession().send(tx, serverMessage, true, false);
            }

            if (retain) {
               boolean reset = payload instanceof EmptyByteBuf || payload.capacity() == 0;
               session.getRetainMessageManager().handleRetainedMessage(serverMessage, topic, reset, tx);
            }
            tx.commit();
         } catch (Throwable t) {
            logger.warn(t.getMessage(), t);
            tx.rollback();
            throw t;
         }
         createMessageAck(messageId, qos, internal);
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:45,代码来源:MQTTPublishManager.java


示例8: decodeLittleEndian

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Override
protected void decodeLittleEndian(
    ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> objects
) throws Exception {
  if (byteBuf instanceof EmptyByteBuf) {
    //TODO: This is a workaround. Check how to prevent calling decode on channel inactive
    return;
  }

  // Header
  final RequestBaseMessage requestBaseMessage = BaseMessageDecoder.decode(
      channelHandlerContext, byteBuf);
  byteBuf.skipBytes(Ints.BYTES);  // Ignore responseTo field in header
  int requestOpCodeInt = byteBuf.readInt();
  RequestOpCode requestOpCode = RequestOpCode.getByOpcode(requestOpCodeInt);
  if (null == requestOpCode) {
    LOGGER.warn(INVALID_OPCODE_MESSAGE + requestOpCodeInt);
    throw new IllegalOperationException(requestOpCodeInt);
  }

  // Body
  MessageDecoder<?> messageDecoder = decoderLocator.getByOpCode(requestOpCode);
  if (null == messageDecoder) {
    LOGGER.error(OPERATION_NOT_IMPLEMENTED + requestOpCode);
    throw new UnsupportedOperationException(OPERATION_NOT_IMPLEMENTED + requestOpCode);
  }

  objects.add(messageDecoder.decode(byteBuf, requestBaseMessage));
}
 
开发者ID:torodb,项目名称:mongowp,代码行数:30,代码来源:RequestMessageByteHandler.java


示例9: closeAfterClientHalfCloseShouldSucceed

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Test
public void closeAfterClientHalfCloseShouldSucceed() throws Exception {
  ListMultimap<CharSequence, CharSequence> expectedHeaders =
      ImmutableListMultimap.copyOf(new DefaultHttp2Headers()
          .status(new AsciiString("200"))
          .set(new AsciiString("content-type"), new AsciiString("application/grpc"))
          .set(new AsciiString("grpc-status"), new AsciiString("0")));

  // Client half-closes. Listener gets halfClosed()
  stream().transportState()
      .inboundDataReceived(new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT), true);

  verify(serverListener).halfClosed();

  // Server closes. Status sent
  stream().close(Status.OK, trailers);
  assertNull("no message expected", listenerMessageQueue.poll());

  ArgumentCaptor<SendResponseHeadersCommand> cmdCap =
      ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
  verify(writeQueue).enqueue(cmdCap.capture(), eq(true));
  SendResponseHeadersCommand cmd = cmdCap.getValue();
  assertThat(cmd.stream()).isSameAs(stream.transportState());
  assertThat(ImmutableListMultimap.copyOf(cmd.headers()))
      .containsExactlyEntriesIn(expectedHeaders);
  assertThat(cmd.endOfStream()).isTrue();

  // Sending and receiving complete. Listener gets closed()
  stream().transportState().complete();
  verify(serverListener).closed(Status.OK);
  assertNull("no message expected", listenerMessageQueue.poll());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:33,代码来源:NettyServerStreamTest.java


示例10: abortStreamAfterClientHalfCloseShouldCallClose

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Test
public void abortStreamAfterClientHalfCloseShouldCallClose() {
  Status status = Status.INTERNAL.withCause(new Throwable());
  // Client half-closes. Listener gets halfClosed()
  stream().transportState().inboundDataReceived(
      new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT), true);
  verify(serverListener).halfClosed();
  // Abort from the transport layer
  stream().transportState().transportReportStatus(status);
  verify(serverListener).closed(same(status));
  assertNull("no message expected", listenerMessageQueue.poll());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:13,代码来源:NettyServerStreamTest.java


示例11: testFilterRequest

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Test
public void testFilterRequest() throws IOException {
	AppConfiguration appConfig = new AppConfiguration(new ConfigLoader(),
			null);
	appConfig.init();

	PolicyManager policyManager = mock(PolicyManager.class);
	NettyRequestProxyFilter filter = new NettyRequestProxyFilter(
			policyManager, appConfig);

	ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
	when(ctx.attr(any(AttributeKey.class))).thenReturn(
			mock(Attribute.class));
	assertNull(filter.filterRequest(mock(HttpRequest.class), ctx));

	DefaultFullHttpRequest req = new DefaultFullHttpRequest(
			HttpVersion.HTTP_1_1, HttpMethod.GET, "http://test.ebay.com/s/");
	when(policyManager.cacheIsNeededFor(any(CacheDecisionObject.class)))
			.thenReturn(false);
	assertNull(filter.filterRequest(req, ctx));

	when(policyManager.cacheIsNeededFor(any(CacheDecisionObject.class)))
			.thenReturn(true);
	CacheManager cm = mock(CacheManager.class);
	when(policyManager.getCacheManager()).thenReturn(cm);
	assertNull(filter.filterRequest(req, ctx));

	FullHttpResponse resp = mock(FullHttpResponse.class);
	HttpHeaders respHeaders = mock(HttpHeaders.class);
	when(resp.headers()).thenReturn(respHeaders);
	when(respHeaders.get(any(CharSequence.class))).thenReturn("100");
	when(cm.get(anyString())).thenReturn(resp);
	Channel channel = mock(Channel.class);
	SocketChannelConfig config = mock(SocketChannelConfig.class);
	when(channel.config()).thenReturn(config);
	when(ctx.channel()).thenReturn(channel);
	req.headers().add("h1", "v1");

	when(resp.content()).thenReturn(
			new EmptyByteBuf(new PooledByteBufAllocator())).thenReturn(
			Unpooled.copiedBuffer("Hello".getBytes()));
	assertEquals(resp, filter.filterRequest(req, ctx));
	assertEquals(resp, filter.filterRequest(req, ctx));
}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:45,代码来源:NettyRequestProxyFilterTest.java


示例12: decode

import io.netty.buffer.EmptyByteBuf; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	if ((in instanceof EmptyByteBuf) || (in.readableBytes() == 0))
		return;
	
   	OperationContext.useHubContext();
   	
	Logger.trace("Decoding Stream Data: " + in.readableBytes());
	
	switch (this.state) {
	case HEADER: {
		if (this.headerparser == null) {
			this.builder = new ObjectBuilder();
			this.headerparser = new BufferToCompositeParser(this.builder);
		}
		
		this.headerparser.parseStruct(in);
		
		// if not done wait for more bytes
		if (!this.headerparser.isDone())
			return;
		
		this.state = State.PAYLOAD_SIZE;
		
		// deliberate fall through 
	}
	case PAYLOAD_SIZE: {
           if (in.readableBytes() < 4) 
               return;
           
           this.size = in.readInt();
		
		this.state = State.PAYLOAD;
		
		// deliberate fall through 
	}
	case PAYLOAD: {
		// return here, without any state reset, means we need more before we can decide what to do
           if (in.readableBytes() < this.size) 
               return;
           
           // we have enough data to send the message...
           StreamMessage msg = new StreamMessage();
           
           // add Data only if there are some bytes, otherwise skip buffer allocation
           if (this.size > 0) {
           	ByteBuf bb = in.readSlice(this.size);
           	bb.retain();
           	msg.setData(bb);
           }
           
           msg.copyFields((RecordStruct) this.builder.getRoot());
		out.add(msg);
           
		// set state to start over - ready to process next message 
		this.headerparser = null;
		this.size = 0;
		this.state = State.HEADER;
	}
	}
}
 
开发者ID:Gadreel,项目名称:divconq,代码行数:62,代码来源:StreamDecoder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Issuer类代码示例发布时间:2022-05-21
下一篇:
Java MethodNode类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap