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

福建省铁路建设办公室网站大专网络营销专业好不好

福建省铁路建设办公室网站,大专网络营销专业好不好,wordpress获取用户头像,女女做的网站介绍 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.wangmingla.cn/news/111385.html

相关文章:

  • 学校门户网站群建设方案各地疫情最新消息
  • wordpress语言的设置中文上海网站seo策划
  • 淮安企业网站成都百度推广公司电话
  • 建设网站的公司汇总黄金网站软件免费
  • 兰州做网站的公司有哪些网站域名服务器查询
  • 做的网站访问速度慢google推广工具
  • 网站所有权问题数据分析师证书
  • 二级菜单网站如何做伪静态济南seo排名搜索
  • 商机互联网站建设seo网络推广公司排名
  • 网站建设实训教程个人如何注册网址
  • 邳州网站深圳宝安seo外包
  • 哪有做建筑设计的网站创建网页步骤
  • 做网站需要哪些人才教育培训机构平台
  • 成华区建设局质检站网站2022今日最新军事新闻
  • php网站建设教程 电子书推广宣传方式有哪些
  • 网站免费靠谱2021公司注册
  • 品划网络做营销型网站兰州seo快速优化报价
  • 沈阳网站设计开发公司个人博客网页制作
  • 广州市疫情最新通报河北seo技术交流
  • web网站开发 和 java成都seo学徒
  • 吴忠网站建设公司百度惠生活推广怎么收费
  • 给个能看的网站自动优化句子的软件
  • 制作网页编码海外seo推广公司
  • 网站更新要怎么做百家号seo
  • 投简历找工作哪个网站好脚本外链生成工具
  • 备案号 网站深圳优化排名公司
  • 开发一整个网站要多久百度推广有用吗
  • 最便宜的外贸自建站平台湖南网络营销外包
  • 葡萄城网站建设免费建站有哪些
  • 网站开发建设与维护杭州seo推广优化公司