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


Java ByteBuf.array方法代码示例

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


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

示例1: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)
  throws Exception {

  byte[] data;
  int offset;
  int length = msg.readableBytes();
  if (msg.hasArray()) {
    data = msg.array();
    offset = msg.arrayOffset();
    msg.skipBytes(length);
  } else {
    data = new byte[length];
    msg.readBytes(data);
    offset = 0;
  }

  out.add(Unpooled.wrappedBuffer(backend.unwrap(data, offset, length)));
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:20,代码来源:SaslEncryption.java

示例2: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
    final byte[] array;
    final int offset;
    final int length = msg.readableBytes();
    if (msg.hasArray()) {
        array = msg.array();
        offset = msg.arrayOffset() + msg.readerIndex();
    } else {
        array = new byte[length];
        msg.getBytes(msg.readerIndex(), array, 0, length);
        offset = 0;
    }

    if (extensionRegistry == null) {
        if (HAS_PARSER) {
            out.add(prototype.getParserForType().parseFrom(array, offset, length));
        } else {
            out.add(prototype.newBuilderForType().mergeFrom(array, offset, length).build());
        }
    } else {
        if (HAS_PARSER) {
            out.add(prototype.getParserForType().parseFrom(array, offset, length, extensionRegistry));
        } else {
            out.add(prototype.newBuilderForType().mergeFrom(array, offset, length, extensionRegistry).build());
        }
    }
}
 
开发者ID:ninelook,项目名称:wecard-server,代码行数:29,代码来源:ProtobufDecoder.java

示例3: getBytesFast

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static byte[] getBytesFast(ByteBuf byteBuf) {
  if (byteBuf.hasArray()) {
    return byteBuf.array();
  }

  byte[] arr = new byte[byteBuf.writerIndex()];
  byteBuf.getBytes(0, arr);
  return arr;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:10,代码来源:VertxUtils.java

示例4: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * 解码
 * 
 * @param in
 * @return
 * @throws Exception
 */
public static LibraMessage decode(ByteBuf in) throws Exception {
	LibraMessage message = new LibraMessage();
	message.setHead(LibraHead.decode(in));
	short bodyLength = in.readShort();// 消息体的长度
	if (bodyLength != in.readableBytes()) {
		LibraLog.error("LibraMessage.decode is error! params:bodyLength:" + bodyLength + "\treadableLength:" + in.readableBytes());
		return null;
	}
	ByteBuf bodyByteBuf = in.readBytes(in.readableBytes());
	byte[] array;
	// 反序列化数据的起始点
	int offset;
	// 可读的数据字节长度
	int readableLen = bodyByteBuf.readableBytes();
	// 分为包含数组数据和不包含数组数据两种形式
	if (bodyByteBuf.hasArray()) {
		array = bodyByteBuf.array();
		offset = bodyByteBuf.arrayOffset() + bodyByteBuf.readerIndex();
	} else {
		array = new byte[readableLen];
		bodyByteBuf.getBytes(bodyByteBuf.readerIndex(), array, 0, readableLen);
		offset = 0;
	}
	// 反序列化
	message.setBody(decodeBody(message.getHead().getProtocolID(), array, offset, readableLen));
	return message;
}
 
开发者ID:inspingcc,项目名称:LibraSock,代码行数:35,代码来源:LibraMessage.java

示例5: heapBuffer

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Listing 5.1
 */
public static void heapBuffer(ByteBuf heapBuf) {
    if (heapBuf.hasArray()) {
    	System.out.println("has array");
        byte[] array = heapBuf.array();
        int offset = heapBuf.arrayOffset() + heapBuf.readerIndex();
        int length = heapBuf.readableBytes();
        System.out.println(offset+" " + length);
        handleArray(array, offset, length);
    }
}
 
开发者ID:zy416548283,项目名称:NettyStudy,代码行数:14,代码来源:ByteBufExamples.java

示例6: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception {

    try {

        logger.debug("Protobuf decode started.");
        in.markReaderIndex();
        if (in.readableBytes() < 4) {
            logger.info("Readable Bytes length less than 4 bytes, ignored");
            in.resetReaderIndex();
            return;
        }

        DataBuffer dataBuf = new DataBuffer(in);

        IMHeader header = new IMHeader();
        header.decode(dataBuf);

        if (header.getLength() < 0) {
            ctx.close();
            logger.error("message length less than 0, channel closed");
            return;
        }

        ByteBuf byteBuf = ctx.alloc().buffer(header.getLength() - SysConstant.PROTOCOL_HEADER_LENGTH);

        in.readBytes(byteBuf);
        byte[] body;
        if (byteBuf.hasArray()) {
            body = byteBuf.array();
        } else {
            body = new byte[byteBuf.capacity()];
            byteBuf.readBytes(body);
        }

        MessageLite msg = ProtobufParseMap.getMessage(header.getServiceId(), header.getCommandId(), body);

        IMProtoMessage<MessageLite> protoMessage = new IMProtoMessage<>(header, msg);
        out.add(protoMessage);
        
        logger.debug("Received protobuf : length={}, commandId={}", header.getLength(), header.getCommandId());
    } catch (Exception e) {
        logger.error(ctx.channel().remoteAddress() + ",decode failed.", e);
    } finally {
        logger.debug("Protobuf decode finished.");
    }
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:48,代码来源:PacketDecoder.java

示例7: addEntityToShop

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static void addEntityToShop ( Account acc, Shop s, int catId, int limit, int cost, String name ) {

		EntityInfo info = new EntityInfo(s.sid, catId, s.cats[catId].getNextMerchId(), 0, Integer.valueOf(cost), acc.manageSession.currentMob, name, limit);
        
        s.cats[catId].addMerch(info);
       
        ModNetworkRegistry . sendToAllAddMerchPacket ( info ) ;

        PreparedStatement pstat = null ;

        try {
          
            ByteBuf buf = Unpooled.buffer();
            
            ByteBufUtils.writeTag(buf, info.entity_data);
            
            InputStream stream = new ByteArrayInputStream(buf.array());
        
            pstat = ModDataBase . getPreparedStatement ( "main", "INSERT INTO " + s.cats[catId].getDatabaseTable() + " (name, data, cost, lim) VALUES(?,?,?,?)");
            
            pstat.setString(1, name);
            pstat.setBlob(2, stream);
            pstat.setInt(3, cost);
            pstat.setInt(4, limit);

            pstat.execute();
            
        } catch ( Exception ex ) {
            
        	ex . printStackTrace ( ) ;
            
        }
        
        ModDataBase . closePreparedStatementAndConnection ( pstat ) ;

	}
 
开发者ID:Pishka,项目名称:MineDonate,代码行数:37,代码来源:ModShopManager.java

示例8: addItemToShop

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static void addItemToShop ( Account acc, Shop s, int catId, int limit, int cost, String name ) {
	
   	ItemInfo info = new ItemInfo(s.sid, catId, s.cats[catId].getNextMerchId(), 0, Integer.valueOf(cost), name, Integer.valueOf(limit), acc.manageSession.currentItemStack);

       PreparedStatement pstat = null ;

       try {
         
       	ByteBuf buf = Unpooled . buffer ( ) ;
        
           NBTTagCompound nbt = new NBTTagCompound ( ) ;
           
           acc . manageSession . currentItemStack . writeToNBT ( nbt ) ;
		acc . manageSession . setItemStack ( null ) ;
           
           s . cats [ catId ] . addMerch ( info ) ;
           
           ModNetworkRegistry . sendToAllAddMerchPacket ( info ) ;
           
           ByteBufUtils.writeTag(buf, nbt);

           InputStream stream = new ByteArrayInputStream(buf.array());
          
           
           if ( s . sid == 0 ) {
           
           	pstat = ModDataBase . getPreparedStatement ( "main", "INSERT INTO " + s.cats[catId].getDatabaseTable() + " (name, cost, lim, stack_data) VALUES(?,?,?,?)");
           
           } else {
        
           	pstat = ModDataBase . getPreparedStatement ( "main", "INSERT INTO " + s.cats[catId].getDatabaseTable() + " (name, cost, lim, stack_data, shopId) VALUES(?,?,?,?,?)");
           	pstat.setInt(5, s.sid);

           }
           
           pstat.setString(1, name);
           pstat.setInt(2, Integer.valueOf(cost));
           pstat.setInt(3, Integer.valueOf(limit));
           pstat.setBlob(4, stream);
           pstat.execute();
           
       } catch ( Exception ex ) {
           
       	ex . printStackTrace ( ) ;
           
       }
       
       ModDataBase . closePreparedStatementAndConnection ( pstat ) ;

}
 
开发者ID:Pishka,项目名称:MineDonate,代码行数:51,代码来源:ModShopManager.java


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