// size = number of records + 1 for additional root element
int nRecords = rRecordStore.getNumRecords() + 1;
byte[] aBuf = null;
DataInputStream aIn = null;
IntArray aIDs = new IntArray(nRecords);
RecordEnumeration aRecords;
aRecords = rRecordStore.enumerateRecords(null, null, false);
aRecordIDs = new Vector(nRecords);
// insert first element as a root that is not part of the RecordStore
aIDs.push(-1);
aRecordIDs.insertElementAt(new NodeRecordIDs(-1, -1), 0);
while (aRecords.hasNextElement())
{
// read all record IDs and store them in ascending order;
// this makes sure that children are always behind their parent
int nID = aRecords.nextRecordId();
int nPos = aIDs.insertAscending(nID, 1);
int nSize = rRecordStore.getRecordSize(nID);
if ((aBuf == null) || (aBuf.length < nSize))
{
// increase buffer size and (re-)initialize the input stream
if (aIn != null)
{
aIn.close();
}
aBuf = new byte[nSize];
aIn = new DataInputStream(new ByteArrayInputStream(aBuf));
}
else
{
aIn.reset();
}
// read parent ID
rRecordStore.getRecord(nID, aBuf, 0);
int nParent = aIn.readInt();
aRecordIDs.insertElementAt(new NodeRecordIDs(nID, nParent),
nPos);
}
if (aIn != null)
{
aIn.close();
}
aRecords.destroy();
}
return aRecordIDs;
}