List of usage examples for java.util.zip ZipFile size
public int size()
From source file:simpleserver.minecraft.MinecraftWrapper.java
private boolean verifyMinecraftJar() { if (getServerJar() != SERVER_JAR) { return true; }/*from w ww. j ava 2 s.com*/ boolean valid = false; try { ZipFile jar = new ZipFile(SERVER_JAR); valid = jar.size() > 200; jar.close(); } catch (IOException e) { } return valid; }
From source file:sebastian.hohns.imagezoom.converter.JImagePyramideProcessor.java
/** * Transforms a list of images and store them at targetPath. * @param imageZip ZipFile with images/*from www .ja v a 2s. co m*/ * @param targetPath target directory * @return true if successful, else false */ public boolean process(ZipFile imageZip, String targetPath) { List<String> images = new ArrayList<String>(imageZip.size()); //Unzip file to tmp dir String tmpPath = System.getProperty("java.io.tmpdir") + File.separator + FilenameUtils.getBaseName(imageZip.getName()); if (!new File(tmpPath).exists()) { new File(tmpPath).mkdirs(); } Enumeration<ZipEntry> pics = (Enumeration<ZipEntry>) imageZip.entries(); ZipEntry entry; try { while (pics.hasMoreElements()) { entry = pics.nextElement(); //Ignore directory and extract all files to tmpdir if (!entry.isDirectory()) { copyInputStream(imageZip.getInputStream(entry), new BufferedOutputStream( new FileOutputStream(FilenameUtils.concat(tmpPath, entry.getName())))); images.add(FilenameUtils.concat(tmpPath, FilenameUtils.getBaseName(entry.getName()))); } } //Call List<String> process boolean result = process(images, targetPath); //Cleanup extracted files cleanup(tmpPath); return result; } catch (IOException ioe) { ioe.printStackTrace(); return false; } }
From source file:VASSAL.tools.io.IOUtilsTest.java
@Test public void testCloseQuietlyZipFileOpen() throws IOException { final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip"); IOUtils.closeQuietly(zf);/* w w w. j a va 2s .com*/ try { zf.size(); fail(); } catch (IllegalStateException e) { // This is the expected behavior of size(). } }
From source file:org.openecomp.sdc.ci.tests.utilities.OnboardingUtils.java
public int countFilesInZipDirectory(String filepath, String filename) throws Exception, Throwable { ZipFile zipFile = new ZipFile(filepath + filename); return zipFile.size() - 1; }
From source file:org.onehippo.repository.bootstrap.InitializationProcessorTest.java
@Test public void testWebFileBundleInitializationFromJar() throws Exception { item.setProperty(HIPPO_WEB_FILE_BUNDLE, "resources"); item.setProperty(HIPPO_EXTENSIONSOURCE, getClass().getResource("/hippo.jar").toString() + "!/hippoecm-extension.xml"); session.save();/* w ww .j a va 2s . c o m*/ final List<PostStartupTask> tasks = process(); assertEquals("There should be one post-startup task", 1, tasks.size()); // test the post-startup task final PostStartupTask importWebFiles = tasks.get(0); Capture<ZipFile> capturedZip = new Capture(); webFilesService.importJcrWebFileBundle(anyObject(Session.class), and(capture(capturedZip), isA(ZipFile.class)), anyBoolean()); expectLastCall(); replay(webFilesService); importWebFiles.execute(); verify(webFilesService); ZipFile zip = capturedZip.getValue(); assertEquals(5, zip.size()); ZipTestUtil.assertEntries(zip, "resources/", "resources/images/", "resources/images/hippo.png", "resources/javascript/", "resources/javascript/hippo.js"); // test reload item.setProperty(HIPPO_RELOADONSTARTUP, true); item.setProperty(HIPPO_STATUS, "pending"); session.save(); final List<PostStartupTask> reloadTasks = process(); assertEquals("There should be one post-startup task after reloading a web file bundle", 1, reloadTasks.size()); final PostStartupTask reimportWebFiles = reloadTasks.get(0); EasyMock.reset(webFilesService); webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(ZipFile.class), anyBoolean()); expectLastCall(); replay(webFilesService); reimportWebFiles.execute(); verify(webFilesService); }
From source file:se.bitcraze.crazyflielib.bootloader.Bootloader.java
/** * Basic check if a file is a Zip file/*from ww w . ja va 2s . c o m*/ * * @param file * @return true if file is a Zip file, false otherwise */ //TODO: how can this be improved? private boolean isZipFile(File file) { if (file != null && file.exists() && file.getName().endsWith(".zip")) { ZipFile zf = null; try { zf = new ZipFile(file); return zf.size() > 0; } catch (ZipException e) { mLogger.error(e.getMessage()); } catch (IOException e) { mLogger.error(e.getMessage()); } finally { if (zf != null) { try { zf.close(); } catch (IOException e) { mLogger.error(e.getMessage()); } } } } return false; }
From source file:com.funambol.framework.tools.FileArchiverTest.java
private void assertDestFileContent(File destFile, List<String> expContent) throws IOException { ZipFile archive = null; try {/*www . j a v a 2s. c om*/ archive = new ZipFile(destFile); Enumeration<? extends ZipEntry> entries = archive.entries(); assertEquals(expContent.size(), archive.size()); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); assertTrue(expContent.contains(entry.getName())); } } finally { if (archive != null) { archive.close(); archive = null; } } }
From source file:org.opencastproject.util.ZipUtilTest.java
@Test public void zipNoRecStrFile() throws Exception { File destFile = new File(destDir, "noRecStrFile.zip"); Vector<String> names = new Vector<String>(); names.add(srcFileName);/* w w w.ja v a 2 s . co m*/ names.add(nestedSrcFileName); File test = ZipUtil.zip(new String[] { srcFile.getCanonicalPath(), nestedSrcFile.getCanonicalPath(), nestedSrcDir.getCanonicalPath() }, destFile, false, ZipUtil.NO_COMPRESSION); Assert.assertTrue(test.exists()); ZipFile zip = new ZipFile(test); Assert.assertEquals(2, zip.size()); Enumeration<? extends ZipEntry> entries = zip.entries(); try { while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); Assert.assertTrue(names.contains(entry.getName())); } } catch (AssertionError ae) { zip.close(); throw ae; } zip.close(); }
From source file:org.opencastproject.util.ZipUtilTest.java
@Test public void zipNoRecFileStr() throws Exception { File destFile = new File(destDir, "noRecFileStr.zip"); Vector<String> names = new Vector<String>(); names.add(srcFileName);/*w ww . jav a 2s. c om*/ names.add(nestedSrcFileName); File test = ZipUtil.zip(new File[] { srcFile, nestedSrcFile, nestedSrcDir }, destFile.getCanonicalPath(), false, ZipUtil.NO_COMPRESSION); Assert.assertTrue(test.exists()); ZipFile zip = new ZipFile(test); Assert.assertEquals(2, zip.size()); Enumeration<? extends ZipEntry> entries = zip.entries(); try { while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); Assert.assertTrue(names.contains(entry.getName())); } } catch (AssertionError ae) { zip.close(); throw ae; } zip.close(); }
From source file:org.opencastproject.util.ZipUtilTest.java
@Test public void zipNoRecFileFile() throws Exception { File destFile = new File(destDir, "noRecFileFile.zip"); Vector<String> names = new Vector<String>(); names.add(srcFileName);// www . j a v a 2 s .co m names.add(nestedSrcFileName); File test = ZipUtil.zip(new File[] { srcFile, nestedSrcFile, nestedSrcDir }, destFile, false, ZipUtil.NO_COMPRESSION); Assert.assertTrue(test.exists()); ZipFile zip = new ZipFile(test); Assert.assertEquals(2, zip.size()); Enumeration<? extends ZipEntry> entries = zip.entries(); try { while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); Assert.assertTrue(names.contains(entry.getName())); } } catch (AssertionError ae) { zip.close(); throw ae; } zip.close(); }