static bool dir2zip_recurse_verbose; static int dir2zip_recurse(File inDir, File zip) { ret dir2zip_recurse(inDir, zip, ""); } // TODO: the zero files case? static int dir2zip_recurse(File inDir, File zip, String outPrefix) ctex { mkdirsForFile(zip); FileOutputStream fout = newFileOutputStream(zip); ZipOutputStream outZip = new ZipOutputStream(fout); try { ret dir2zip_recurse(inDir, outZip, outPrefix, 0); } finally { outZip.close(); } } static int dir2zip_recurse(File inDir, ZipOutputStream outZip) { ret dir2zip_recurse(inDir, outZip, "", 0); } static int dir2zip_recurse(File inDir, ZipOutputStream outZip, String outPrefix, int level) ctex { if (++level >= 20) fail("woot? 20 levels in zip?"); new L files; for (File f : listFiles(inDir)) files.add(f); int n = 0; sortFilesByName(files); for (File f : files) { if (f.isDirectory()) { if (dir2zip_recurse_verbose) print("dir2zip_recurse: Scanning " + f.getAbsolutePath()); n += dir2zip_recurse(f, outZip, outPrefix + f.getName() + "/", level); } else { if (dir2zip_recurse_verbose) print("Copying " + f.getName()); outZip.putNextEntry(new ZipEntry(outPrefix + f.getName())); InputStream fin; try { fin = new FileInputStream(f); } catch e { print(e); continue; } temp fin; copyStream(fin, outZip); ++n; } } return n; }