} os.writeInt(termCount);
} os.writeInt(storedOccurencesList.getTermCount());
		public void reindex(DocumentImpl document, StoredNode node) {            final short collectionId = document.getCollection().getId();		    final Lock lock = dbTokens.getLock();            for (byte currentSection = 0; currentSection <= ATTRIBUTE_SECTION; currentSection++) {		        for (Iterator i = words[currentSection].entrySet().iterator(); i.hasNext();) {                                       //Compute a key for the token                    Map.Entry entry = (Map.Entry) i.next();                    String token = (String) entry.getKey();                                        WordRef ref = new WordRef(collectionId, token);                    OccurrenceList storedOccurencesList = (OccurrenceList) entry.getValue();                    os.clear();                     		            try {		                lock.acquire(Lock.WRITE_LOCK);                        VariableByteInput is = dbTokens.getAsStream(ref);	                        //Does the token already has data in the index ?		                if (is != null) {		                    //Add its data to the new list    		                    try {		                        while (is.available() > 0) {                                    int storedDocId = is.readInt();                                    byte storedSection = is.readByte();                                    int termCount = is.readInt();                                    //TOUNDERSTAND -pb                                             int size = is.readFixedInt();		                            if (storedSection != currentSection || storedDocId != document.getDocId()) {                                        // data are related to another section or document:                                        // append them to any existing data		                                os.writeInt(storedDocId);		                                os.writeByte(storedSection);		                                os.writeInt(termCount);		                                os.writeFixedInt(size);		                                is.copyRaw(os, size);		                            } else {                                        // data are related to our section and document:                                        // feed the new list with the GIDs                                        long previousGID = 0;		                                for (int j = 0; j < termCount; j++) {                                            long delta = is.readLong();                                            long storedGID = previousGID + delta;                                            int freq = is.readInt();		                                    if (node == null) {		                                        if (document.getTreeLevel(storedGID) < document.getMetadata().reindexRequired()) {                                                    for (int l = 0; l < freq; l++) {                                                        //Note that we use the existing list                                                        storedOccurencesList.add(storedGID, is.readInt());                                                    }                                                } else                                                    is.skip(freq);                                                		                                    } else {		                                        if (!NodeSetHelper.isDescendantOrSelf(                                                        document,                                                        node.getGID(),                                                        storedGID)) {                                                    for (int l = 0; l < freq; l++) {                                                        //Note that we use the existing list                                                        storedOccurencesList.add(storedGID, is.readInt());                                                    }                                                } else                                                    is.skip(freq);                                            }                                            previousGID = storedGID;		                                }		                            }		                        }		                    } catch (EOFException e) {		                        //EOF is expected here		                    }		                }                        if (storedOccurencesList.getSize() > 0) {                            //append the data from the new list                            int termCount = storedOccurencesList.getTermCount();                            storedOccurencesList.sort();                            		                os.writeInt(document.getDocId());                            switch (currentSection) {                                case TEXT_SECTION :                                    os.writeByte(TEXT_SECTION);                                    break;                                case ATTRIBUTE_SECTION :                                    os.writeByte(ATTRIBUTE_SECTION);                                    break;                                default :                                    throw new IllegalArgumentException("Invalid section type in '" + dbTokens.getFile().getName() +                                         "' (inverted index)");                            }             		                os.writeInt(termCount);                            //TOUNDERSTAND -pb                                     int lenOffset = os.position();    	                    os.writeFixedInt(0);                                                        long previousGID = 0;                            for (int m = 0; m < storedOccurencesList.getSize(); ) {                                long delta = storedOccurencesList.nodes[m] - previousGID;                                os.writeLong(delta);                                                            int freq = storedOccurencesList.getOccurrences(m);                                os.writeInt(freq);                                for (int n = 0; n < freq; n++) {                                    os.writeInt(storedOccurencesList.offsets[m + n]);                                }                                previousGID = storedOccurencesList.nodes[m];                                m += freq;                            }		                    		                os.writeFixedInt(lenOffset, os.position() - lenOffset - 4);                        }		                //Store the data		                	                    if (is == null) {                            //TOUNDERSTAND : Should is be null, what will there be in os.data() ? -pb	                        if (dbTokens.put(ref, os.data()) == BFile.UNKNOWN_ADDRESS) {                                LOG.error("Could not put index data for token '" +  token + "' in '" + dbTokens.getFile().getName() +                                         "' (inverted index)");                            }	                    } else {                              long address = ((BFile.PageInputStream) is).getAddress();	                        if (dbTokens.update(address, ref, os.data()) == BFile.UNKNOWN_ADDRESS) {                                LOG.error("Could not update index data for value '" +  token +  "' in '" + dbTokens.getFile().getName() +                                     "' (inverted index)");                             }	                    }		                		            } catch (LockException e) {                        LOG.warn("Failed to acquire lock for '" + dbTokens.getFile().getName() + "' (inverted index)", e);		                                   } catch (ReadOnlyException e) {                        LOG.warn("Read-only error on '" + dbTokens.getFile().getName() + "' (inverted index)", e);                        		            } catch (IOException e) {		                LOG.error("io error while reindexing word '" + token  + "' in '" + dbTokens.getFile().getName() + "' (inverted index)", e);		               		            } finally {		                lock.release(Lock.WRITE_LOCK);		            }		        }		        words[currentSection].clear();		    }		}