* true for success, false for failure to find the header information.
* */
private BPTreeNode readBPTreeNode(SeekableStream fis, long fileOffset,
BPTreeNode parent, boolean isLowToHigh){
LittleEndianInputStream lbdis = null; // low to high byte reader
DataInputStream bdis = null; // high to low byte reader
// set up for node format
byte[] buffer = new byte[BPTREE_NODE_FORMAT_SIZE];
BPTreeNode thisNode = null;
BPTreeNode childNode = null;
byte type;
byte bval;
int itemCount;
int itemSize;
boolean isLeaf;
try {
// Read node format into a buffer
fis.seek(fileOffset);
fis.readFully(buffer);
if(isLowToHigh)
lbdis = new LittleEndianInputStream(new ByteArrayInputStream(buffer));
else
bdis = new DataInputStream(new ByteArrayInputStream(buffer));
// find node type
if(isLowToHigh)
type = lbdis.readByte();
else
type = bdis.readByte();
// create the B+ tree node
if(type == 1) {
isLeaf = true;
thisNode = new BPTreeLeafNode(++nodeCount);
}
else {
isLeaf = false;
thisNode = new BPTreeChildNode(++nodeCount);
}
if(isLowToHigh) {
bval = lbdis.readByte(); // reserved - not currently used
itemCount = lbdis.readShort();
}
else {
bval = bdis.readByte(); // reserved - not currently used
itemCount = bdis.readShort();
}
// Note: B+ tree node item size is the same for leaf and child items
itemSize = BPTREE_NODE_ITEM_SIZE + this.keySize;
int totalSize = itemSize * itemCount;
byte[] itemBuffer = new byte[totalSize];
fis.readFully(itemBuffer);
if(isLowToHigh)
lbdis = new LittleEndianInputStream(new ByteArrayInputStream(itemBuffer));
else
bdis = new DataInputStream(new ByteArrayInputStream(itemBuffer));
// get the node items - leaves or child nodes
for(int item = 0; item < itemCount; ++item) {
// always extract the key from the node format
char[] keychars = new char[keySize]; // + 1 for 0 byte
int index;
for(index = 0; index < keySize; ++index) {
if(isLowToHigh)
bval = lbdis.readByte();
else
bval = bdis.readByte();
keychars[index] = (char)bval;
}
String key = new String(keychars).trim();
int chromID;
int chromSize;
long childOffset;
if(isLeaf) {
if(isLowToHigh) {
chromID = lbdis.readInt();
chromSize = lbdis.readInt();
}
else {
chromID = bdis.readInt();
chromSize = bdis.readInt();
}
// insert leaf items
BPTreeLeafNodeItem leafItem = new BPTreeLeafNodeItem(++leafCount, key, chromID, chromSize);
thisNode.insertItem(leafItem);
}
else {
// get the child node pointed to in the node item
if(isLowToHigh)
childOffset = lbdis.readLong();
else
childOffset = bdis.readLong();
childNode = readBPTreeNode(this.fis, childOffset, thisNode, isLowToHigh);