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

重庆网站建设齐重庆零臻科技国产免费crm系统有哪些

重庆网站建设齐重庆零臻科技,国产免费crm系统有哪些,建e网app下载,优书网注册介绍 Netty的ByteBuf数据位置索引是0开始的。 可以用ByteBuf的getByte(int index)方法从指定位置读出一字节,这个操作不会改变ByteBuf的readerIndex 或者 writerIndex 的位置。如果index小于0,或者index 1大于ByteBuf的容量,就会抛出IndexO…

介绍

Netty的ByteBuf数据位置索引是0开始的。
可以用ByteBuf的getByte(int index)方法从指定位置读出一字节,这个操作不会改变ByteBuf的readerIndex 或者 writerIndex 的位置。如果index小于0,或者index + 1大于ByteBuf的容量,就会抛出IndexOutOfBoundsException异常。
可以用ByteBuf的readByte()方法从当前readerIndex 读出一字节,并且将readerIndex 的值增加1。如果ByteBuf的readableBytes的值小于1,就会抛出IndexOutOfBoundsException异常。
可以使用ByteBuf的isReadable()方法判断是否有可读的数据。当(this.writerIndex - this.readerIndex) 的值大于0,isReadable()返回true。

writeShort(int value)函数:在ByteBuf的当前writerIndex位置开始写入一个16位的整数,并且将writerIndex增加2。因为输入参数是int型,占4个字节,高位的16位被丢弃。
getShort(int index)函数:从ByteBuf的绝对位置index开始,读取1个16位的整数。这个方法不改变ByteBuf的readerIndex 和 writerIndex。

代码举例

用getByte(int index)方法正常读取数据

代码:

package com.thb;import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;public class Test {public static void main(String[] args) {		ByteBuf buf = Unpooled.buffer(1);		for (int i = 0; i < 1; i++) {buf.writeByte(0x68);}for (int i = 0; i < buf.capacity(); i++) {System.out.println(buf.getByte(i));}}}

运行输出:
在这里插入图片描述

用getByte(int index)方法不正常读取数,据抛出异常

代码:

package com.thb;import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;public class Test {public static void main(String[] args) {		ByteBuf buf = Unpooled.buffer(1);		for (int i = 0; i < 1; i++) {buf.writeByte(0x68);}for (int i = 0; i < buf.capacity() + 1; i++) {System.out.println(buf.getByte(i));}}}

运行输出:
在这里插入图片描述

用readByte()方法正常读取数据–用readableBytes()判断可读的数据字节数

代码:

package com.thb;import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;public class Test {public static void main(String[] args) {		ByteBuf buf = Unpooled.buffer(2);		for (int i = 0; i < 2; i++) {buf.writeByte(0x68);}		while (buf.readableBytes() > 0) {System.out.println(buf.readByte());}}}

运行输出:
在这里插入图片描述

用readByte()方法正常读取数据–用isReadable()判断是否有可读的数据

代码:

package com.thb;import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;public class Test {public static void main(String[] args) {		ByteBuf buf = Unpooled.buffer(2);		for (int i = 0; i < 2; i++) {buf.writeByte(0x68);}		while (buf.isReadable()) {System.out.println(buf.readByte());}}}

运行输出:
在这里插入图片描述

用getBytes(int index, byte[] dst)读取部分内容到数组中

getBytes(int index, byte[] dst)表示从ByteBuf的绝对位置index开始,拷贝部分内容到目的字节数组中。这个操作不改变ByteBuf的readerIndex 和 writerIndex。

package com.thb;import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;public class Test {public static void main(String[] args) {		ByteBuf buf = Unpooled.buffer(4);for (int i = 0; i < buf.capacity(); i++) {buf.writeByte(0x68);}byte[] data = new byte[2];// 从buf的第二个字节开始,拷贝2个字节的内容到data数组中buf.getBytes(1, data);System.out.println("数组data的内容:");for (int i = 0; i < data.length; i++) {System.out.println(data[i]);}System.out.println("buf的内容:");for (int i = 0; i < buf.capacity(); i++) {System.out.println(buf.getByte(i));}}}

运行结果:
在这里插入图片描述

用writeShort(int value)写入一个short型整数,用getShort(int index)读取一个short型整数

package com.thb;import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;public class Test {public static void main(String[] args) {		ByteBuf buf = Unpooled.buffer(4);buf.writeShort(2048);// 从buf中读取一个short型整数并打印出来,看是否和传入的相同System.out.println("从ByteBuf中读取的short型整数为:" + buf.getShort(0));}}

运行结果:
在这里插入图片描述

http://www.yayakq.cn/news/280632/

相关文章:

  • 网站开发搜索功能wordpress 主题模板下载失败
  • 青岛专业网站建设推广报价数字营销策略有哪些
  • 酷站是什么网站网站建设丶金手指下拉11
  • 网站开发的价格seo关键词排名优化价格
  • 网站建设类的职位易站网站建设
  • wordpress关键词位置宁波seo优势
  • 企业大学网站建设计划个人主页网站设计论文
  • 服务器租用1元河南seo推广公司
  • 做网站刷东西珠海模板建站平台
  • 自己公司内网网站和外网怎么做同步品牌搜索引擎服务优化
  • 怎样做直播网站一键急速安装wordpress
  • 傻瓜使用模板建网站做门窗做什么网站好
  • 池州网站建设兼职wordpress伪造ip
  • 网站管理人员队伍建设说明材料室内设计行业现状及发展前景
  • 硬件开发工资高吗南阳做网站seo的
  • 凡科网站建设网站做外贸是网站好还是展会好
  • 哈尔滨住房和城乡建设局网站首页wordpress中文主题下载
  • 关于域名用于非网站用途的承诺书重庆市任免干部
  • 威海建设网站淄博建站哪家好
  • 最新购物网站建设框架wordpress文章自动内链
  • 小企业如何建网站91卫星地图手机版下载官网
  • wordpress京东客系统wordpress 数据库优化
  • 可以免费做网站推广的平台火星培训机构收费明细
  • wordpress网站更改主题信息网站做跳转微信打开
  • 网站后台管理系统 asp做物业管理的企业网站
  • 怎么提高网站转化率合肥网站的优化
  • 网站到底备案好不好潍坊信息网网站建设
  • 营销网站的策划方案怎么做html代码编写
  • 电子商务网站的开发原则包括海南的网站建设公司
  • 企业网站价格花数据库主机wordpress