VariableByteOutputStream os = new VariableByteOutputStream();
	public void flush() {		if (elementIds.size() == 0)			return;		final ProgressIndicator progress = new ProgressIndicator(elementIds.size());		NodeProxy proxy;		String elementName;		ArrayList idList;		int count = 1, len;		byte[] data;		String name;		Value ref;		Map.Entry entry;		VariableByteOutputStream os = new VariableByteOutputStream();		// get collection id for this collection		final String docName = doc.getFileName();		long prevId;		long cid;		long addr;		short collectionId = doc.getCollection().getId();		Lock lock = dbElement.getLock();		try {			for (Iterator i = elementIds.entrySet().iterator(); i.hasNext();) {				entry = (Map.Entry) i.next();				elementName = (String) entry.getKey();				idList = (ArrayList) entry.getValue();				i.remove();				FastQSort.sort(idList, 0, idList.size() - 1);				len = idList.size();				os.writeInt(doc.getDocId());				os.writeInt(len);				prevId = 0;				for (int j = 0; j < len; j++) {					proxy = (NodeProxy) idList.get(j);					cid = proxy.gid - prevId;					prevId = proxy.gid;					os.writeLong(cid);					StorageAddress.write(proxy.internalAddress, os);				}				data = os.toByteArray();				os.clear();				short sym = NativeBroker.getSymbols().getSymbol(elementName);				ref = new NativeBroker.ElementValue(collectionId, sym);				try {					lock.acquire(Lock.WRITE_LOCK);					if (dbElement.append(ref, data) < 0) {						LOG.warn("could not save index for element " + elementName);						continue;					}				} catch (LockException e) {					LOG.error("could not acquire lock on elements", e);				} finally {					lock.release();				}				progress.setValue(count);				setChanged();				notifyObservers(progress);				count++;			}		} catch (ReadOnlyException e) {			LOG.warn("database is read-only");			return;		}		elementIds.clear();		//elementIds = new TreeMap();	}