}
private final int pageOutSegments(final FixedSegments paged, final int beginPage, boolean toend)
throws IOException {
final long[][] blockRef = _block;
final FastMultiByteArrayOutputStream buf = new FastMultiByteArrayOutputStream(DEFAULT_EXTENT_SIZE);
final long lp = (_blockPtr >> PAGE_SHIFT) + 1;
if(lp > 0x7fffffffL) {
throw new IllegalStateException("Illegal page number: " + lp);
}
final int usedPages = (int) lp;
int cnt = 0;
for(int i = beginPage; i <= usedPages; i += DEFAULT_EXTENT_THRESHOLD) {
final int pages;
if((i + DEFAULT_EXTENT_THRESHOLD) > usedPages) {
if(!toend) {
break;
}
pages = usedPages - i;
} else {
pages = DEFAULT_EXTENT_THRESHOLD;
}
int addr = i;
final int limit = Math.min(i + pages, blockRef.length);
for(int p = i; p < limit; p++) {
final long[] ref = blockRef[p];
if(ref == null) {
if(buf.size() > 0) {
final byte[] b = buf.toByteArray();
buf.reset();
paged.bulkWrite(addr, b);
}
} else {
if(buf.size() == 0) {
addr = p;
}
buf.writeLongs(ref, 0, ref.length);
blockRef[p] = null;
++cnt;
}
}
if(buf.size() > 0) {
final byte[] b = buf.toByteArray();
buf.reset();
paged.bulkWrite(addr, b);
}
}
buf.close();
paged.flush(false);
if(LOG.isInfoEnabled()) {
LOG.info("paged out docuemnt table seqment(" + beginPage + " - " + (beginPage + cnt)
+ ") to disk: " + paged.getFile().getAbsolutePath());
}