os.clear();
    public void flush() {        //TODO : return if doc == null? -pb                if (pending.size() == 0)             return;                     final short collectionId = this.doc.getCollection().getId();        final Lock lock = dbValues.getLock();        for (Iterator i = pending.entrySet().iterator(); i.hasNext();) {            Map.Entry entry = (Map.Entry) i.next();            Indexable indexable = (Indexable) entry.getKey();            //TODO : NativeElementIndex uses ArrayLists -pb            ArrayList gids = (ArrayList) entry.getValue();            int gidsCount = gids.size();            //Don't forget this one            FastQSort.sort(gids, 0, gidsCount - 1);                        os.clear();            os.writeInt(this.doc.getDocId());            os.writeInt(gidsCount);            int lenOffset = os.position();            os.writeFixedInt(0);            //Compute the GID list            for (int j = 0; j < gidsCount; j++) {                                    NodeId nodeId = (NodeId) gids.get(j);                try {                    nodeId.write(os);                } catch (IOException e) {                    LOG.warn("IO error while writing range index: " + e.getMessage(), e);                }            }            os.writeFixedInt(lenOffset, os.position() - lenOffset - 4);                        try {                lock.acquire(Lock.WRITE_LOCK);                                Value key = new Value(indexable.serialize(collectionId, caseSensitive));                if (dbValues.append(key, os.data()) == BFile.UNKNOWN_ADDRESS) {                    LOG.error("Could not append index data for key '" +  key + "'");                                   }			} catch (EXistException e) {                LOG.error(e.getMessage(), e);                            } catch (LockException e) {                LOG.warn("Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e);               //TODO : return ?                                     } catch (IOException e) {                LOG.error(e.getMessage(), e);                  //TODO : return ?            } catch (ReadOnlyException e) {                LOG.warn(e.getMessage(), e);                     //Return without clearing the pending entries                return;                             } finally {                lock.release();            }        }        pending.clear();    }