-
Notifications
You must be signed in to change notification settings - Fork 2
HybridStream heep direct buffer & memory file stream混用BIO
RockyLOMO edited this page Apr 14, 2022
·
1 revision
内部支持 heep / direct buffer,当memory stream超过阈值后自动切换为file stream。
@Test
public void hybridStream() {
int[] maxSizes = new int[]{35, 70};
for (int max : maxSizes) {
HybridStream stream = new HybridStream(max, null);
testSeekStream(stream);
long position = stream.getPosition();
System.out.println(position);
stream.write(content);
assert stream.getPosition() == position + content.length && stream.getLength() == stream.getPosition();
byte[] data = new byte[(int) stream.getLength()];
stream.setPosition(0L);
stream.read(data);
System.out.println(new String(data));
}
}