OutputStream os = bucket.getOutputStream();
os.write(buf.clone());
os.close();
assertTrue(bucket.isRAMBucket());
assertEquals(len, bucket.size());
TempRandomAccessBuffer raf = (TempRandomAccessBuffer) bucket.toRandomAccessBuffer();
bucket.getInputStream().close(); // Can read.
try {
bucket.getOutputStream(); // Cannot write.
fail();
} catch (IOException e) {
// Ok.
}
assertEquals(len, raf.size());
assertFalse(raf.hasMigrated());
checkArrayInner(buf, raf, len, r);
// Now migrate to disk.
raf.migrateToDisk();
File f = ((PooledFileRandomAccessBuffer) raf.getUnderlying()).file;
assertTrue(f.exists());
assertEquals(len, f.length());
assertTrue(raf.hasMigrated());
assertEquals(factory.getRamUsed(), 0);
checkArrayInner(buf, raf, len, r);
checkBucket(bucket, buf);
raf.close();
raf.free();
assertFalse(f.exists());
}