java.nio.Buffer源码是什么
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,这篇文章主要介绍"java.nio.Buffer源码是什么",在日常操作中,相信很多人在java.nio.Buffer源码是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家
千家信息网最后更新 2025年02月02日java.nio.Buffer源码是什么
这篇文章主要介绍"java.nio.Buffer源码是什么",在日常操作中,相信很多人在java.nio.Buffer源码是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"java.nio.Buffer源码是什么"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
版本:JDK7
package java.nio;
public abstract class Buffer {
// mark <= position <= limit <= capacityprivate int mark = -1; // 标记,一个特定的position,通过mark()方法指定Buffer中的标记,之后可以通过reset()方法恢复到这个索引位置private int position = 0; // 下一个要读取或写入的数据的索引private int limit; // 界限,表示缓冲区中可操作数据的大小,索引等于和大于limit的数据不能进行读写。private int capacity; // 缓冲区的容量,创建后不能修改。// Used only by direct buffers// NOTE: hoisted here for speed in JNI GetDirectBufferAddresslong address;// Creates a new buffer with the given mark, position, limit, and capacity,Buffer(int mark, int pos, int lim, int cap) { if (cap < 0) throw new IllegalArgumentException("Negative capacity: " + cap); this.capacity = cap; limit(lim); position(pos); if (mark >= 0) { if (mark > pos) throw new IllegalArgumentException("mark > position: (" + mark + " > " + pos + ")"); this.mark = mark; }}public final int capacity() { return capacity;}public final int position() { return position;}// 重新设置position的值public final Buffer position(int newPosition) { if ((newPosition > limit) || (newPosition < 0)) throw new IllegalArgumentException(); position = newPosition; if (mark > position) mark = -1; return this;}public final int limit() { return limit;}// 重新设置limit的值:如果新limit小于position,则将position设为新limitpublic final Buffer limit(int newLimit) { if ((newLimit > capacity) || (newLimit < 0)) throw new IllegalArgumentException(); limit = newLimit; if (position > limit) position = limit; if (mark > limit) mark = -1; return this;}// 设置标记public final Buffer mark() { mark = position; return this;}// 将position的值设置为markpublic final Buffer reset() { int m = mark; if (m < 0) throw new InvalidMarkException(); position = m; return this;}// 清空缓冲区:Buffer的属性恢复到初始化状态。注意:此时缓冲区中的数据仍然存在。public final Buffer clear() { position = 0; limit = capacity; mark = -1; return this;}// 将limit设为当前的position,之后将position重置为0public final Buffer flip() { limit = position; position = 0; mark = -1; return this;}// 将position设为0,并取消设置的标记:即重新读Bufferpublic final Buffer rewind() { position = 0; mark = -1; return this;}// 返回剩余的可用空间public final int remaining() { return limit - position;}// 判断缓冲区中是否还有元素public final boolean hasRemaining() { return position < limit;}public abstract boolean isReadOnly();public abstract boolean hasArray();public abstract Object array();public abstract int arrayOffset();public abstract boolean isDirect();// -- Package-private methods for bounds checking, etc. --// ...
}
到此,关于"java.nio.Buffer源码是什么"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
缓冲区
缓冲
源码
数据
标记
学习
方法
索引
更多
帮助
实用
接下来
位置
元素
可以通过
大小
容量
属性
文章
版本
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
专升本网络技术基础用哪本书
激战2 哪个服务器强
服务器生存模式视频教程
服务器外接移动硬盘备份数据
网络安全技术体系建设
重装上阵怎么进入服务器
无锡计算机软件开发机构
qq炫舞服务器下载慢怎么办
香肠派对国际服能不能选择服务器
数据库服务启动灰色的
高校网络安全法宣传活动报道
30台机器搭建游戏服务器
保证国家网络安全需从
计算机二级有没有网络技术
鹰皇金佰仕网络技术
信访局网络安全检查总结报告
网络安全协管员辅警
狮子座互联网科技培训
性教育管理数据库
金华电脑软件开发教程
数据库绝对路径
辽宁优质软件开发价格
三五互联网科技有限公司
湘雅医院网络安全招聘
医院网络技术招聘
云数据库polardb使用
计算机网络安全初探
业务软件开发合同注意事项
网络安全安全宣传实践活动纪实
dfs文件服务器部署