class HeapCharBuffer extends CharBuffer {
// 调用CharBuffer的构造函数
// CharBuffer(int mark, int pos, int lim, int cap, char[] hb, int offset) {
// super(mark, pos, lim, cap);
// this.hb = hb;
// this.offset = offset;
// }
HeapCharBuffer(int cap, int lim) {
super(-1, 0, lim, cap, new char[cap], 0);
}
HeapCharBuffer(char[] buf, int off, int len) {
super(-1, off, off + len, buf.length, buf, 0);
}
protected HeapCharBuffer(char[] buf, int mark, int pos, int lim, int cap,
int off) {
super(mark, pos, lim, cap, buf, off);
}
//返回
public CharBuffer slice() {
return new HeapCharBuffer(hb, -1, 0, this.remaining(),
this.remaining(), this.position() + offset);
}
public CharBuffer duplicate() {
return new HeapCharBuffer(hb, this.markValue(), this.position(),
this.limit(), this.capacity(), offset);
}
public CharBuffer asReadOnlyBuffer() {
return new HeapCharBufferR(hb, this.markValue(), this.position(),
this.limit(), this.capacity(), offset);
}
protected int ix(int i) {
return i + offset;
}
//获取缓冲区中当前位置的元素,然后pos++
public char get() {
return hb[ix(nextGetIndex())];
}
//返回当前位置的元素
public char get(int i) {
return hb[ix(checkIndex(i))];
}
//
public CharBuffer get(char[] dst, int offset, int length) {
checkBounds(offset, length, dst.length);
if (length > remaining())
throw new BufferUnderflowException();
System.arraycopy(hb, ix(position()), dst, offset, length);
position(position() + length);
return this;
}
public boolean isDirect() {
return false;
}
public boolean isReadOnly() {
return false;
}
//
public CharBuffer put(char x) {
hb[ix(nextPutIndex())] = x;
return this;
}
public CharBuffer put(int i, char x) {
hb[ix(checkIndex(i))] = x;
return this;
}
public CharBuffer put(char[] src, int offset, int length) {
checkBounds(offset, length, src.length);
if (length > remaining())
throw new BufferOverflowException();
System.arraycopy(src, offset, hb, ix(position()), length);
position(position() + length);
return this;
}
public CharBuffer put(CharBuffer src) {
if (src instanceof HeapCharBuffer) {
if (src == this)
throw new IllegalArgumentException();
HeapCharBuffer sb = (HeapCharBuffer) src;
int n = sb.remaining();
if (n > remaining())
throw new BufferOverflowException();
System.arraycopy(sb.hb, sb.ix(sb.position()), hb, ix(position()), n);
sb.position(sb.position() + n);
position(position() + n);
} else if (src.isDirect()) {
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
src.get(hb, ix(position()), n);
position(position() + n);
} else {
super.put(src);
}
return this;
}
public CharBuffer compact() {
System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
position(remaining());
limit(capacity());
return this;
}
String toString(int start, int end) { // package-private
try {
return new String(hb, start + offset, end - start);
} catch (StringIndexOutOfBoundsException x) {
throw new IndexOutOfBoundsException();
}
}
// --- Methods to support CharSequence ---
public CharSequence subSequence(int start, int end) {
if ((start < 0) || (end > length()) || (start > end))
throw new IndexOutOfBoundsException();
int pos = position();
return new HeapCharBuffer(hb, -1, pos + start, pos + end, capacity(),
offset);
}
public ByteOrder order() {
return ByteOrder.nativeOrder();
}
}
分享到:
相关推荐
《TMS320F28x源码解读——深入理解数字信号处理器的精髓》 在数字信号处理领域,TMS320F28x系列芯片因其高性能、低功耗的特点,被广泛应用于各种复杂系统中,如工业自动化、电力控制、通信设备等。这些系统的核心...
4500页的源码解读 光是SELECT语句相关实现,就阐述了300多页 看完了你就是postgreSQL达人了 章节明细,需要精读那个功能点就仔细看
Netty5.0架构剖析和源码解读 本文档主要讲述了Netty5.0架构剖析和源码解读,涵盖了Netty的架构、源码分析、NIO入门等方面的知识点。 概述 JAVA 的 IO 演进是一个长期的过程,从传统的 BIO 通信到 NIO 的出现,都...
源码解读是软件开发中的一项重要技能,它涉及到对程序源代码的深入理解和分析,以揭示系统的功能实现和设计思路。在《源码解读的基本原理》中,我们了解到源码解读能够帮助我们理解系统的运作机制,提升编程能力,并...
首先,源码解读对于任何开发者来说都是提升技术能力的重要途径。通过阅读源码,我们可以更直观地了解框架的工作原理,从而更好地利用它。Spring框架的设计理念和实现方式对许多其他Java框架产生了深远影响,因此深入...
本篇文章将详细解读QCAD的源码,涵盖编译配置过程以及核心设计理念。 首先,让我们从编译QCAD源码开始。QCAD主要基于C++编写,因此你需要一个支持C++11或更高版本的编译器,如GCC或Clang。在Linux系统上,通常使用`...
《Resin源码解读》 Resin,作为一个高性能的Java应用服务器,其源码解析对于我们深入理解Web服务器的运行机制和优化技术具有重要的价值。本文将从日志分析、运行时调试、网络模型以及线程池模型四个方面进行深入...
Netty5.0 架构剖析和源码解读 作者:李林锋 版权所有 email neu_lilinfeng@ © Netty5.0 架构剖析和源码解读1 1. 概述2 1.1. JAVA 的IO演进2 1.1.1. 传统BIO通信的弊端2 1.1.2. Linux 的网络IO模型简介4 1.1.3. IO...
Spark-2.3.1源码解读。 Spark Core源码阅读 Spark Context 阅读要点 Spark的缓存,变量,shuffle数据等清理及机制 Spark-submit关于参数及部署模式的部分解析 GroupByKey VS ReduceByKey OrderedRDDFunctions...
STM32开发板三轴联动插补源码解读,直线圆弧加减速功能解析,基于STM32F1与STM32F4源码研究,附带大量中文注释,助力学习与实践应用,基于STM32开发板的三轴联动插补直线圆弧源码解读及基于STM32F系列加速减速功能...
VxWorks以其高效、确定性和微秒级的响应时间著称,它的源码解读对于我们理解其工作原理、优化系统性能以及进行定制化开发具有重要意义。 首先,我们要了解VxWorks的核心组成部分,包括内核(Kernel)、文件系统...
本文将针对"Vue进阶面试题,源码解读,含Vue3源码解读"这一主题,详细探讨相关知识点。 首先,对于Vue进阶面试题,通常会涉及到以下几个方面: 1. **响应式原理**:Vue基于ES6的Proxy和Reflect实现数据的响应式,...
在《PX4源码解读》中,我们可以深入探讨这个系统的核心组成部分和工作原理。首先,PX4的架构由几个关键模块组成: 1. **硬件抽象层**:这层代码确保了PX4可以适应各种硬件平台,包括不同类型的传感器、处理器和通信...
Spring Boot源码解析是深入了解Spring Boot内部工作原理和机制的重要途径。通过源码分析,开发者可以更好地理解Spring Boot的自动装配、启动流程以及如何自定义启动器。Spring Boot的自动装配原理涉及到Spring Boot...
JEECMS2源码的解读,介绍JEECMS2源码的结构,开发流程等
综上所述,“Pixhawk源码总结.pdf”这份文档详细介绍了Pixhawk的软件架构、关键算法以及源码解读,对于想要深入学习开源飞控系统的人来说,是一份宝贵的参考资料。通过阅读和实践,开发者可以更好地掌握无人机飞行...
这本书旨在帮助开发者深入理解OSG的内部工作原理,通过详细解读源码,提升开发者的技能和应用能力。 OSG的核心源码解析主要包括以下几个关键部分: 1. **数据结构与设计模式**:OSG中大量使用了面向对象的设计模式...
spring源码,spring源码,spring源码,spring源码,spring源码,spring源码,pring源码,spring源码,spring源码,spring源码,spring源码,spring源码,spring源码,pring源码,pring源码,pring源码,pring源码,...
HashMap 之 put 方法源码解读 HashMap 是 Java 中一种常用的数据结构,用于存储键值对。其中,put 方法是 HashMap 中最重要的方法之一,负责将键值对存储到HashMap 中。在本文中,我们将对 HashMap 的 put 方法的...