DocumentSet docs = new DocumentSet(); try { ArrayList collList = null; synchronized (collectionsDb) { collList = collectionsDb.getEntries(); } if (collList == null) return docs;  Value val; Value[] entry; byte[] data; VariableByteInputStream istream; DocumentImpl doc; Collection collection; String collName; for (int i = 0; i < collList.size(); i++) { entry = (Value[]) collList.get(i); collName = entry[0].toString(); if (collName.startsWith("__")) continue; collection = collections.get(collName); if(collection == null) { val = entry[1]; data = val.getData(); istream = new VariableByteInputStream(data); collection = new Collection(this, collName); collection.read(istream); } if (collection .getPermissions() .validate(user, Permission.READ)) for (Iterator iter = collection.iterator(); iter.hasNext(); ) { doc = (DocumentImpl) iter.next(); if (doc .getPermissions() .validate(user, Permission.READ)) { docs.add(doc); } }  } } catch (BTreeException dbe) { LOG.error(dbe); } catch (IOException ioe) { LOG.debug(ioe); }
Collection root = getCollection("/db"); DocumentSet docs = root.allDocs(user);
	public DocumentSet getAllDocuments(User user) {		long start = System.currentTimeMillis();		DocumentSet docs = new DocumentSet();		try {			ArrayList collList = null;			synchronized (collectionsDb) {				collList = collectionsDb.getEntries();			}			if (collList == null)				return docs;			Value val;			Value[] entry;			byte[] data;			VariableByteInputStream istream;			DocumentImpl doc;			Collection collection;			String collName;			for (int i = 0; i < collList.size(); i++) {				entry = (Value[]) collList.get(i);				collName = entry[0].toString();				if (collName.startsWith("__"))					continue;				collection = collections.get(collName);				if(collection == null) {					val = entry[1];					data = val.getData();					istream = new VariableByteInputStream(data);					collection = new Collection(this, collName);					collection.read(istream);				}				if (collection					.getPermissions()					.validate(user, Permission.READ))					for (Iterator iter = collection.iterator();						iter.hasNext();						) {						doc = (DocumentImpl) iter.next();						if (doc							.getPermissions()							.validate(user, Permission.READ)) {							docs.add(doc);						}					}			}		} catch (BTreeException dbe) {			LOG.error(dbe);		} catch (IOException ioe) {			LOG.debug(ioe);		}		LOG.debug(			"loading "				+ docs.getLength()				+ " documents took "				+ (System.currentTimeMillis() - start)				+ "ms.");		return docs;	}