public void testBucketToRAF() throws IOException {
Random r = new Random(6032405);
int length = 1024*64+1;
byte[] data = new byte[length];
RandomAccessBucket bucket = (RandomAccessBucket) makeBucket(length);
OutputStream os = bucket.getOutputStream();
r.nextBytes(data);
for(int written=0;written<length;) {
int toWrite = Math.min(length - written, 4095);
os.write(data, written, toWrite);
written += toWrite;
}
os.close();
InputStream is = bucket.getInputStream();
for(int moved=0;moved<length;) {
int readBytes = Math.min(length - moved, 4095);
byte[] buf = new byte[readBytes];
readBytes = is.read(buf);
assertTrue(readBytes > 0);
assertTrue(Arrays.equals(Arrays.copyOfRange(buf, 0, readBytes), Arrays.copyOfRange(data, moved, moved+readBytes)));
moved += readBytes;
}
LockableRandomAccessBuffer raf = bucket.toRandomAccessBuffer();
assertEquals(length, raf.size());
RAFBucket wrapped = new RAFBucket(raf);
assertTrue(BucketTools.equalBuckets(bucket, wrapped));
for(int i=0;i<100;i++) {
int end = length == 1 ? 1 : r.nextInt(length)+1;