byte[] data = ostream.toByteArray();
	public void addDocument(Collection collection, DocumentImpl doc)		throws PermissionDeniedException {		Value name;		try {			name = new Value(collection.getName().getBytes("UTF-8"));		} catch (UnsupportedEncodingException uee) {			LOG.debug(uee);			name = new Value(collection.getName().getBytes());		}		try {			storeDocument(doc);			VariableByteOutputStream ostream = new VariableByteOutputStream();			doc.write(ostream);			byte[] data = ostream.toByteArray();			Lock lock = collectionsDb.getLock();			try {				lock.acquire();				long address = collectionsDb.append(name, data);				if (address < 0) {					LOG.debug("could not store collection data for " + collection.getName());					return;				}				collection.setAddress(address);				if (!name.equals("/db")) {					Collection parent = collection.getParent();					parent.update(collection);					saveCollection(parent);				}			} catch (LockException e) {				LOG.warn("failed to lock collections store", e);			} finally {				lock.release();			}		} catch (IOException ioe) {			LOG.debug(ioe);		} catch (ReadOnlyException e) {			LOG.warn("database is read-only");		}	}