2.5 Gathering Writes

简介: 2.5 Gathering Writes

使用如下方式写入,可以将多个 buffer 的数据填充至 channel

try (RandomAccessFile file = new RandomAccessFile("helloword/3parts.txt", "rw")) { FileChannel channel = file.getChannel(); ByteBuffer d = ByteBuffer.allocate(4); ByteBuffer e = ByteBuffer.allocate(4); channel.position(11);


d.put(new byte[]{'f', 'o', 'u', 'r'});
e.put(new byte[]{'f', 'i', 'v', 'e'});
d.flip();
e.flip();
debug(d);
debug(e);
channel.write(new ByteBuffer[]{d, e});

} catch (IOException e) { e.printStackTrace(); }

结果 +-------------------------------------------------+ |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f | +--------+-------------------------------------------------+----------------+ |00000000| 66 6f 75 72                                     |four            | +--------+-------------------------------------------------+----------------+ +-------------------------------------------------+ |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f | +--------+-------------------------------------------------+----------------+ |00000000| 66 69 76 65                                     |five

文件内容 onetwothreefourfive|


目录
相关文章
|
3月前
|
监控 NoSQL Redis
Asynchronous AOF fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting for fsync to complete, this may slow down Redis.
Asynchronous AOF fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting for fsync to complete, this may slow down Redis.
|
6月前
PGA memory operation
PGA memory operation
72 1
|
6月前
|
前端开发 JavaScript
Synchronous
Synchronous(同步)和sync(同步函数)是JavaScript中用于处理同步操作的关键概念。
75 2
2.4 Scattering Reads
2.4 Scattering Reads
48 0
|
存储 缓存 分布式计算
译|Eventually Consistent
译|Eventually Consistent
55 0
|
关系型数据库 MySQL
Consistent Nonlocking Reads,Locking Reads 和Phantom Rows
以Consistent Nonlocking Reads,Locking Reads为突破点,用简单的例子来说明mysql常用的事务隔离级别(READ COMMITTED, REPEATABLE READ)和lock(record lock,gap lock,next-key lock, Insert Intention Lock)的关系
Consistent Nonlocking Reads,Locking Reads 和Phantom Rows
|
关系型数据库
### avoid read-on-write
### avoid read-on-write 什么是 "read-on-write" problem? 在我们使用最常见的buffer write 中 "read-on-write" 问题指的是当我需要进行小于4k 大小buffer write 的时候, 需要先将数据所在的page 从disk 中读取出放入到page cache, 在page cache 中修改好, 然后再将
1488 0
|
SQL 关系型数据库 Oracle
|
SQL 关系型数据库 索引
ORA-19566 exceeded limit of 0 corrupt blocks数据坏块处理
    问题描述 RMAN备份失败,报错如下:   channel ch1: starting piece 1 at 02-NOV-12 released channel: ch1 RMAN-00571: R...
2033 0