private File[] getSortedFiles(boolean reverse) throws IOException {
		fileSync.lock();
		try {
			File[] files = dir.listFiles();
			List<File> cpFiles = new ArrayList<File>(files.length);
			long highestId = 0;
			for (int i = 0; i < files.length; i++) {
				int id = getId(files[i]);
				if (id != -1) {
					cpFiles.add(files[i]);
					if ((id & 0xFFFFFFFFL) > highestId) {
						highestId = id;
					}
				}
			}
			if (getNextId(highestId) == -1) {
				throw new IOException("Exhausted filename space");
			}
			Collections.sort(cpFiles, fileComparator);
			if (reverse) {
				Collections.reverse(cpFiles);
			}
			return cpFiles.toArray(new File[0]);
		} finally {
			fileSync.unlock();
		}
	}