* */
static RPTreeNode readRPTreeNode(SeekableStream fis, long fileOffset, boolean isLowToHigh, boolean forceDescend) {
LittleEndianInputStream lbdis = null; // low o high byte stream reader
DataInputStream bdis = null; // high to low byte stream reader
byte[] buffer = new byte[RPTREE_NODE_FORMAT_SIZE];
RPTreeNode thisNode = null;
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
byte type;
if (isLowToHigh) {
type = lbdis.readByte();
} else {
type = bdis.readByte();
}
boolean isLeaf;
int itemSize;
if (type == 1) {
isLeaf = true;
itemSize = RPTREE_NODE_LEAF_ITEM_SIZE;
thisNode = new RPTreeNode(true);
} else {
isLeaf = false;
itemSize = RPTREE_NODE_CHILD_ITEM_SIZE;
thisNode = new RPTreeNode(false);
}
//nodeCount++;
int itemCount;
if (isLowToHigh) {
lbdis.readByte(); // reserved - not currently used
itemCount = lbdis.readShort();
} else {
bdis.readByte(); // reserved - not currently used
itemCount = bdis.readShort();
}
int itemBlockSize = itemCount * itemSize;
buffer = new byte[itemBlockSize]; // allocate buffer for item sisze
fis.readFully(buffer);
if (isLowToHigh)
lbdis = new LittleEndianInputStream(new ByteArrayInputStream(buffer));
else
bdis = new DataInputStream(new ByteArrayInputStream(buffer));
// get the node items - leaves or child nodes
int startChromID, endChromID;
int startBase, endBase;
for (int item = 0; item < itemCount; ++item) {
// always extract the bounding rectangle
if (isLowToHigh) {
startChromID = lbdis.readInt();
startBase = lbdis.readInt();
endChromID = lbdis.readInt();
endBase = lbdis.readInt();
} else {
startChromID = bdis.readInt();
startBase = bdis.readInt();
endChromID = bdis.readInt();
endBase = bdis.readInt();
}
if (isLeaf) {
long dataOffset;
long dataSize;
if (isLowToHigh) {
dataOffset = lbdis.readLong();
dataSize = lbdis.readLong();
} else {
dataOffset = bdis.readLong();
dataSize = bdis.readLong();
}
thisNode.insertItem(new RPTreeLeafNodeItem(startChromID, startBase, endChromID, endBase,
dataOffset, dataSize));
} else {
// get the child node pointed to in the node item
long nodeOffset;
if (isLowToHigh) {
nodeOffset = lbdis.readLong();
} else {
nodeOffset = bdis.readLong();
}
// Recursive call to read next child node