os.writeInt(gidsCount); is.copyTo(os, gidsCount);
os.writeInt(gidsCount); os.writeFixedInt(size); is.copyRaw(os, size);
    public void remove() {         //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            LongLinkedList storedGIDList = (LongLinkedList) entry.getValue();               //Compute a key for the value            Value searchKey = new Value(indexable.serialize(collectionId, caseSensitive));            //TODO : NativeElementIndex uses ArrayLists -pb            LongLinkedList newGIDList = new LongLinkedList();            os.clear();                          try {                                    lock.acquire(Lock.WRITE_LOCK);                 Value value = dbValues.get(searchKey);                //Does the value already has data in the index ?                if (value != null) {                    //Add its data to the new list                    VariableByteArrayInput is = new VariableByteArrayInput(value.getData());                    try {                                                    while (is.available() > 0) {                            int storedDocId = is.readInt();                            int gidsCount = is.readInt();                            if (storedDocId != this.doc.getDocId()) {                                // data are related to another document:                                // append them to any existing data                                os.writeInt(storedDocId);                                os.writeInt(gidsCount);                                                                                                       is.copyTo(os, gidsCount);                            } else {                                // data are related to our document:                                // feed the new list with the GIDs                                long previousGID = 0;                                for (int j = 0; j < gidsCount; j++) {                                    long delta = is.readLong();                                    long storedGID = previousGID + delta;                                      // add the node to the new list if it is not                                     // in the list of removed nodes                                    if (!storedGIDList.contains(storedGID)) {                                        newGIDList.add(storedGID);                                    }                                    previousGID = storedGID;                                }                            }                        }                    } catch (EOFException e) {                        //Is it expected ? if not, remove the block -pb                        LOG.warn("REPORT ME " + e.getMessage(), e);                    }                    //append the data from the new list                    if (newGIDList.getSize() > 0) {                                                long[] gids = newGIDList.getData();                        int gidsCount = gids.length;                        //Don't forget this one                        Arrays.sort(gids);                        os.writeInt(this.doc.getDocId());                        os.writeInt(gidsCount);                        long previousGID = 0;                        for (int j = 0; j < gidsCount; j++) {                            long delta = gids[j] - previousGID;                                                        os.writeLong(delta);                            previousGID = gids[j];                        }                     }                }                                //Store the data                if (value == null) {                    if (dbValues.put(searchKey, os.data()) == BFile.UNKNOWN_ADDRESS) {                        LOG.error("Could not put index data for value '" +  searchKey + "'");                      }                                    } else {                    if (dbValues.update(value.getAddress(), searchKey, os.data()) == BFile.UNKNOWN_ADDRESS) {                        LOG.error("Could not update index data for value '" +  searchKey + "'");                      }                                    }              } catch (LockException e) {                LOG.warn("Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e);                //TODO : return ?            } catch (ReadOnlyException e) {                LOG.warn("Read-only error on '" + dbValues.getFile().getName() + "'", e);            } catch (IOException e) {                LOG.error(e.getMessage(), e);                            } finally {                lock.release();            }                    }        pending.clear();    }    