/*$Id$*/
package at.jku.sii.sqlitereader.page;
import java.util.ArrayList;
import java.util.List;
import at.jku.sii.sqlitereader.SqliteDataBase;
import at.jku.sii.sqlitereader.io.ArrayDataInput;
public final class PayloadOverflowPage implements Page {
private final int nextPageNum;
private final int number;
private final ArrayDataInput data;
public PayloadOverflowPage(int number, int nextPageNum, ArrayDataInput in) {
this.nextPageNum = nextPageNum;
this.data = in;
this.number = number;
}
@Override
public int getNumber() {
return this.number;
}
public static List<PayloadOverflowPage> readOverflowPages(SqliteDataBase db, int startPage) {
List<PayloadOverflowPage> list = new ArrayList<PayloadOverflowPage>();
int page = startPage;
while (page > 0) {
ArrayDataInput block = db.getPageBlock(page);
int nextPage = block.readInt();
block.annotateLastInt("nextPage", nextPage);
int size = block.size() - 4;
byte[] content = new byte[size];
block.readFully(content);
block.annotateLast(content.length, "Payload");
ArrayDataInput in = new ArrayDataInput(content, block.createLastSubAnnotator(content.length));
PayloadOverflowPage p = new PayloadOverflowPage(page, nextPage, in);
list.add(p);
db.resolvePage(page, p);
page = nextPage;
}
return list;
}
public int getNextPageNum() {
return this.nextPageNum;
}
public ArrayDataInput getData() {
return this.data;
}
@Override
public String toString() {
return String.format("PayloadOverflowPage [nextPageNum=%s]", this.nextPageNum);
}
@Override
public void dump(StringBuilder b) {
b.append("<h3>PayloadOverflow Page ").append(this.number).append("</h3>\n");
}
}