private void archiveDirectories(ZipOutputStream out) throws IOException {
int numThreads = Settings.getInt("slowNetwork.numParallelReads", 10);
ExecutorService service = Executors.newFixedThreadPool(
Math.max(numThreads, 1));
DrainableExecutor executor = new DrainableExecutor(service);
exceptionEncountered = null;
NumberFormat fmt = NumberFormat.getIntegerInstance();
fmt.setMinimumIntegerDigits(3);
Set<String> extDirNames = new HashSet<String>();
extDirNames.add(null); extDirNames.add("");
for (int i = 0; i < importInstructions.size(); i++) {
ImportDirectoryInstruction instr = importInstructions.get(i);
String newPath = getExtDirName(instr);
if (extDirNames.contains(newPath))
newPath = "extdir" + fmt.format(i + 1);
extDirNames.add(newPath);
executor.execute(new ArchiveDirectoryTask(executor, out, instr,
newPath));
}
executor.drain();
if (exceptionEncountered != null)
throw exceptionEncountered;
}