mark 和 reset

简介: mark 和 reset

mark 是在读取时,做一个标记,即使 position 改变,只要调用 reset 就能回到 mark 的位置

注意

rewind 和 flip 都会清除 mark 位置

字符串与 ByteBuffer 互转

ByteBuffer buffer1 = StandardCharsets.UTF_8.encode("你好"); ByteBuffer buffer2 = Charset.forName("utf-8").encode("你好");

debug(buffer1); debug(buffer2);

CharBuffer buffer3 = StandardCharsets.UTF_8.decode(buffer1); System.out.println(buffer3.getClass()); System.out.println(buffer3.toString());

结果 +-------------------------------------------------+ |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f | +--------+-------------------------------------------------+----------------+ |00000000| e4 bd a0 e5 a5 bd                               |......          | +--------+-------------------------------------------------+----------------+ +-------------------------------------------------+ |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f | +--------+-------------------------------------------------+----------------+ |00000000| e4 bd a0 e5 a5 bd                               |......          | +--------+-------------------------------------------------+----------------+ class java.nio.HeapCharBuffer 你好


目录
相关文章
|
6天前
智能指针 reset weakptr
智能指针 reset weakptr
36 0
|
6天前
|
存储 Java
10.对象头、Mark Word、monitor、synchronized怎么关联起来?
10.对象头、Mark Word、monitor、synchronized怎么关联起来?
47 0
10.对象头、Mark Word、monitor、synchronized怎么关联起来?
|
9月前
|
测试技术
Pytest-mark标记的其他方法
Pytest-mark标记的其他方法
27 0
|
10月前
|
测试技术
13-pytest-自定义mark标记
13-pytest-自定义mark标记
|
11月前
|
SQL 安全 Dubbo
mark好文章
mark好文章
46 0
|
测试技术
Pytest系列(8) - 使用自定义标记mark
Pytest系列(8) - 使用自定义标记mark
89 0
Pytest系列(8) - 使用自定义标记mark
|
Oracle 算法 Java
Control+Break在JVM中的处理
在 Oracle Solaris 或 Linux 操作系统上, 在应用程序控制台 (标准输入) 中按下Ctrl控制键和反斜线 (\) 键的组合会导致 Java 热点 VM 将线程转储打印到应用程序的标准输出。在 Windows 上, 等效的键序列是控件和中断键。这些组合键的一般术语是Control + Break 处理程序。
189 0
|
数据安全/隐私保护
SmartSVN无法提交的解决办法:because it was moved from which is not part of the commit; both sides of the move
SmartSVN无法提交的解决办法:because it was moved from which is not part of the commit; both sides of the move
337 0