protected static void zip(Blob blob, ZipOutputStream out) throws IOException { String entry = getFileName(blob); InputStream in = blob.getStream(); try { ZipUtils._zip(entry, in, out); } finally { in.close(); } }
protected static void zip(List<Blob> blobs, ZipOutputStream out) throws IOException { // use a set to avoid zipping entries with same names Collection<String> names = new HashSet<String>(); int cnt = 1; for (Blob blob : blobs) { String entry = getFileName(blob); if (!names.add(entry)) { entry = "renamed_" + (cnt++) + "_" + entry; } InputStream in = blob.getStream(); try { ZipUtils._zip(entry, in, out); } finally { in.close(); } } }
public static void zip(File[] files, OutputStream out, String prefix) throws IOException { try (ZipOutputStream zout = new ZipOutputStream(out)) { _zip(files, zout, prefix); } }
public static void _putFileEntry(File file, String entryName, ZipOutputStream out) throws IOException { try (FileInputStream in = new FileInputStream(file)) { _zip(entryName, in, out); } }
public static void _zip(File[] files, ZipOutputStream out, String prefix) throws IOException { String normalizedPrefix = normalizePrefix(prefix); for (File file : files) { String name = normalizedPrefix + file.getName(); _zip(name, file, out); } }
public static void _zip(String entryName, File file, ZipOutputStream out) throws IOException { // System.out.println("Compressing "+entryName); if (file.isDirectory()) { entryName += '/'; ZipEntry zentry = new ZipEntry(entryName); out.putNextEntry(zentry); out.closeEntry(); File[] files = file.listFiles(); for (File child : files) { _zip(entryName + child.getName(), child, out); } } else { InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); _zip(entryName, in, out); } finally { if (in != null) { in.close(); } } } }
public static void zip(File file, OutputStream out, String prefix) throws IOException { prefix = normalizePrefix(prefix); String name = normalizePrefix(prefix) + file.getName(); try (ZipOutputStream zout = new ZipOutputStream(out)) { _zip(name, file, zout); } }