lock.acquire(this, Lock.WRITE_LOCK); lock.enter(this);
lock.acquire(Lock.WRITE_LOCK);
		public void remove() {			if(doc == null)				return;			final short collectionId = doc.getCollection().getId();			int len, docId;			Map.Entry entry;			String word;			LongLinkedList idList;			long[] ids;			byte[] data;			long last, gid;			long delta;			NodeProxy p;			WordRef ref;			LongLinkedList newList;			Value val = null;			VariableByteInputStream is;			VariableByteOutputStream os = new VariableByteOutputStream();			Lock lock = dbWords.getLock();			for (Iterator i = words.entrySet().iterator(); i.hasNext();) {				entry = (Map.Entry) i.next();				word = (String) entry.getKey();				idList = (LongLinkedList) entry.getValue();				ref = new WordRef(collectionId, word);				try {					lock.acquire(this, Lock.READ_LOCK);					lock.enter(this);					val = dbWords.get(ref);				} catch (LockException e) {					LOG.error("could not acquire lock on index for '" + word + "'");				} finally {					lock.release(this);				}				os.clear();				newList = new LongLinkedList();				if (val != null) {					// add old entries to the new list 					data = val.getData();					is = new VariableByteInputStream(data);					try {						while (is.available() > 0) {							docId = is.readInt();							len = is.readInt();							if (docId == doc.getDocId()) {								// copy data to new buffer; skip								// removed nodes								last = 0;								for (int j = 0; j < len; j++) {									delta = is.readLong();									last = last + delta;									if (!idList.contains(last))										newList.add(last);								}							} else {								// section belongs to another document:								// copy data to new buffer								os.writeInt(docId);								os.writeInt(len);								for (int j = 0; j < len; j++) {									//delta = is.readLong();									//os.writeLong(delta);									is.copyTo(os);								}							}						}					} catch (EOFException e) {						LOG.error("end-of-file while reading index entry for " + word);					} catch (IOException e) {						LOG.error("io-error while reading index entry for " + word);					}				}				ids = newList.getData();				i.remove();				Arrays.sort(ids);				len = ids.length;				os.writeInt(doc.getDocId());				os.writeInt(len);				last = 0;				for (int j = 0; j < len; j++) {					delta = ids[j] - last;					if (delta < 0) {						LOG.debug("neg. delta: " + delta + " for " + word);						LOG.debug("id = " + ids[j] + "; prev = " + last);					}					os.writeLong(delta);					last = ids[j];				}				data = os.toByteArray();				try {					lock.acquire(this, Lock.WRITE_LOCK);					lock.enter(this);					try {						if (val == null)							dbWords.put(ref, data);						else							dbWords.update(val.getAddress(), ref, data);					} catch (ReadOnlyException e) {					}				} catch (LockException e) {					LOG.warn("could not acquire lock", e);				} finally {					lock.release(this);				}			}			words.clear();		}