/** * Zips a file or a folder. * @see #zip(java.io.File) */ public static File zip(String file) throws IOException { return zip(new File(file)); }
/** * Zips a file or a folder. * @see #zip(java.io.File) */ public static File zip(final String file) throws IOException { return zip(new File(file)); }
@Test void testZip() throws IOException { ZipUtil.zip(new File(dataRoot, "sb.data")); File zipFile = new File(dataRoot, "sb.data.zip"); assertTrue(zipFile.exists()); // cleanup FileUtil.delete(zipFile); ZipUtil.zip(new File(dataRoot, "file")); zipFile = new File(dataRoot, "file.zip"); assertTrue(zipFile.exists()); // cleanup FileUtil.delete(zipFile); }
@Test void testZipDir() throws IOException { ZipUtil.zip(new File(dataRoot)); File zipFile = new File(dataRoot + ".zip"); assertTrue(zipFile.exists()); int directoryCount = 0; try (ZipFile zipfile = new ZipFile(zipFile)) { for (Enumeration<? extends ZipEntry> entries = zipfile.entries(); entries.hasMoreElements(); ) { ZipEntry zipEntry = entries.nextElement(); if (zipEntry.isDirectory()) { directoryCount++; assertTrue(zipEntry.getName().equals("data/") || zipEntry.getName().equals("data/file/")); } } } assertEquals(2, directoryCount); // cleanup FileUtil.delete(zipFile); }
/** * Zips a file or a folder. * @see #zip(java.io.File) */ public static File zip(final String file) throws IOException { return zip(new File(file)); }