当前位置: 首页 > news >正文

优秀营销网站设计学跨境电商要多少钱

优秀营销网站设计,学跨境电商要多少钱,今天的新闻有哪些,免费学做美食视频网站有哪些文章目录 概念Pre概述ByteBuf简介ByteBuf的主要特性结构APIByteBuf的创建读写操作示例引用计数操作其他常用操作 Code 演示 概念 Pre Netty Review - 探索ByteBuf的内部机制 概述 Netty的ByteBuf是一个强大的字节容器#xff0c;用于处理字节数据。它提供了比Java标准库中的… 文章目录 概念Pre概述ByteBuf简介ByteBuf的主要特性结构APIByteBuf的创建读写操作示例引用计数操作其他常用操作 Code 演示 概念 Pre Netty Review - 探索ByteBuf的内部机制 概述 Netty的ByteBuf是一个强大的字节容器用于处理字节数据。它提供了比Java标准库中的ByteBuffer更灵活和高效的方式来操作字节数据。 ByteBuf简介 Netty的ByteBuf是一个字节容器它提供了一种更灵活和高效的方式来操作字节数据。与ByteBuffer不同ByteBuf具有可扩展的缓冲区可以动态调整容量而不需要创建新的缓冲区对象。 ByteBuf的主要特性 可读性和可写性 ByteBuf具有读和写两种模式。读操作和写操作是相互独立的因此可以在不同的操作中使用同一段数据。零拷贝 ByteBuf支持零拷贝操作这意味着可以直接操作底层内存而无需将数据复制到中间缓冲区。引用计数 ByteBuf使用引用计数来跟踪对缓冲区的活动引用这有助于防止内存泄漏。 结构 ByteBuf有三个关键的指针分别是readerIndex、writerIndex和capacity。 readerIndex表示读操作的起始位置writerIndex表示写操作的起始位置capacity表示ByteBuf的容量 从结构上来说ByteBuf 由一串字节数组构成。数组中每个字节用来存放信息。 ByteBuf 提供了两个索引一个用于读取数据一个用于写入数据。这两个索引通过在字节数组中移动来定位需要读或者写信息的位置。 读写操作 通过readerIndex和writerIndex来进行读写操作支持顺序读写和随机读写 当从 ByteBuf 读取时它的 readerIndex读索引将会根据读取的字节数递增。 同样当写 ByteBuf 时它的 writerIndex 也会根据写入的字节数进行递增。 需要注意的是极限的情况是 readerIndex 刚好读到了 writerIndex 写入的地方。 如果 readerIndex 超过了 writerIndex 的时候Netty 会抛出 IndexOutOf-BoundsException 异常。 API ByteBuf的创建 ByteBuf buffer Unpooled.buffer(10); // 创建一个初始容量为10的ByteBuf读写操作示例 // 写入数据 buffer.writeBytes(Hello.getBytes());// 读取数据 byte[] data new byte[buffer.readableBytes()]; buffer.readBytes(data); System.out.println(new String(data));引用计数操作 // 引用计数 1 buffer.retain();// 引用计数 -1如果引用计数为0则释放相关资源 buffer.release();其他常用操作 获取和设置索引位置的字节值。查找指定字节或字节数组的位置。派发读/写索引而不实际移动数据。 Code 演示 import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.util.CharsetUtil;public class NettyByteBuf {public static void main(String[] args) {// 创建byteBuf对象该对象内部包含一个字节数组byte[14]// 通过readerindex和writerIndex和capacity将buffer分成三个区域// 已经读取的区域[0,readerindex)// 可读取的区域[readerindex,writerIndex)// 可写的区域: [writerIndex,capacity)ByteBuf byteBuf Unpooled.buffer(14);System.out.println(byteBuf byteBuf);printBytebuf(byteBuf);System.out.println();for (int i 0; i 8; i) {byteBuf.writeByte(i);}System.out.println(byteBuf byteBuf);printBytebuf(byteBuf);System.out.println();for (int i 0; i 5; i) {System.out.println(byteBuf.getByte(i));}System.out.println(byteBuf byteBuf);printBytebuf(byteBuf);System.out.println();for (int i 0; i 5; i) {System.out.println(byteBuf.readByte());}System.out.println(byteBuf byteBuf);printBytebuf(byteBuf);System.out.println();//用Unpooled工具类创建ByteBufString text hello,artisan! ;ByteBuf byteBuf2 Unpooled.copiedBuffer(text , CharsetUtil.UTF_8);//使用相关的方法if (byteBuf2.hasArray()) {byte[] content byteBuf2.array();//将 content 转成字符串System.out.println(new String(content, CharsetUtil.UTF_8));System.out.println(byteBuf2 byteBuf2);printBytebuf(byteBuf2);System.out.println();// 获取数组0这个位置的字符h的ascii码h104System.out.println(byteBuf2.getByte(0));System.out.println();//可读的字节数 14int len byteBuf2.readableBytes();System.out.println(len len);printBytebuf(byteBuf2);System.out.println();//使用for取出各个字节for (int i 0; i len; i) {System.out.println((char) byteBuf2.getByte(i));}printBytebuf(byteBuf2);System.out.println();//范围读取System.out.println(byteBuf2.getCharSequence(0, 6, CharsetUtil.UTF_8));printBytebuf(byteBuf2);System.out.println();System.out.println(byteBuf2.getCharSequence(6, 8, CharsetUtil.UTF_8));printBytebuf(byteBuf2);}}public static void printBytebuf(ByteBuf byteBuf){System.out.println(readerIndex: byteBuf.readerIndex());System.out.println(writerIndex: byteBuf.writerIndex());System.out.println(capacity: byteBuf.capacity());} } 输出 byteBufUnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 14) readerIndex:0 writerIndex:0 capacity:14byteBufUnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 8, cap: 14) readerIndex:0 writerIndex:8 capacity:140 1 2 3 4 byteBufUnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 8, cap: 14) readerIndex:0 writerIndex:8 capacity:140 1 2 3 4 byteBufUnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 5, widx: 8, cap: 14) readerIndex:5 writerIndex:8 capacity:14hello,artisan! byteBuf2UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 14, cap: 42) readerIndex:0 writerIndex:14 capacity:42104len14 readerIndex:0 writerIndex:14 capacity:42h e l l o , a r t i s a n ! readerIndex:0 writerIndex:14 capacity:42hello, readerIndex:0 writerIndex:14 capacity:42artisan! readerIndex:0 writerIndex:14 capacity:42
http://www.zqtcl.cn/news/196474/

相关文章:

  • wordpress 分类文章置顶整站优化推广品牌
  • 网站手机验证码如何做官方网站在家做兼职
  • 东莞三合一网站制作网站建设 千助
  • 114网站做推广怎么样江苏建设培训网站
  • 如何让网站做网页适配网站上的产品五星怎样做优化
  • 怎么做网站排名优化免费jq网站模板
  • 源码时代培训机构官网自己建网站怎么做seo
  • 宜都网站制作济南比较大的网站制作公司
  • 怎么用电脑做网站主机假网站怎么制作
  • 网站 微信网络营销方案设计心得
  • 淘宝客 wordpress网站wordpress类似的工具
  • 农村建设房子建设网站建设渭南房产网站制作
  • php网站开发用什么win2008 iis 新建网站
  • 中山营销网站建设杭州网站建设开发有限公司
  • 被他人备案后做违法网站抖音seo推广
  • 手机网站广告代码南靖县建设局网站
  • 郑州网站建设智巢高德地图有外资背景吗
  • 网站开发常遇到客户问题wordpress怎么升级
  • 网站的空间是网站 建设 维护 公司
  • 关于网站建设的书籍网站设计的趋势
  • 临漳+网站建设深圳国贸网站建设
  • 安全的南昌网站制作上海网站建设网
  • 360网站制作潍坊医疗网站建设方案
  • 深圳网站策划公司域名解析暂时失败
  • 怎么做安居客网站wordpress 函数文件
  • 微名片网站怎么做html代码表示
  • 两学一做纪实评价系统网站如何做好百度推广
  • 网站设置手机才能播放企业网站开发需求
  • 网站建设微信运营销售做网站用啥语言
  • dw建设网站步骤活动汪活动策划网站