當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipFile.getEntries方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.zip.ZipFile.getEntries方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipFile.getEntries方法的具體用法?Java ZipFile.getEntries怎麽用?Java ZipFile.getEntries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.zip.ZipFile的用法示例。


在下文中一共展示了ZipFile.getEntries方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractZip

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private void extractZip(ZipFile zipFile) {
  Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {

    ZipArchiveEntry entry = entries.nextElement();
    String fileName = entry.getName();
    File outputFile = new File(config.getExtractionFolder(), fileName);

    if (entry.isDirectory()) {
      makeDirectory(outputFile);
    } else {
      createNewFile(outputFile);
      try {
        InputStream inputStream = zipFile.getInputStream(entry);
        extractFile(inputStream, outputFile, fileName);
      } catch (IOException e) {
        throw new ExtractionException("Error extracting file '" + fileName + "' "
            + "from downloaded file: " + config.getDownloadTarget(), e);
      }
    }
  }
}
 
開發者ID:AlejandroRivera,項目名稱:embedded-rabbitmq,代碼行數:23,代碼來源:BasicExtractor.java

示例2: TestBarInstaller

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * barファイル內エントリのファイルサイズ上限値を超えた場合に例外が発生すること.
 */
@Test
public void barファイル內エントリのファイルサイズ上限値を超えた場合に例外が発生すること() {
    TestBarInstaller testBarInstaller = new TestBarInstaller();
    URL fileUrl = ClassLoader.getSystemResource("requestData/barInstall/V1_1_2_bar_minimum.bar");
    File file = new File(fileUrl.getPath());

    try {
        ZipFile zipFile = new ZipFile(file, "UTF-8");
        Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
        long maxBarEntryFileSize = 0;
        while (entries.hasMoreElements()) {
            ZipArchiveEntry zae = entries.nextElement();
            if (zae.isDirectory()) {
                continue;
            }
            testBarInstaller.checkBarFileEntrySize(zae, zae.getName(), maxBarEntryFileSize);
        }
        fail("Unexpected exception");
    } catch (PersoniumCoreException dce) {
        String code = PersoniumCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE.getCode();
        assertEquals(code, dce.getCode());
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:29,代碼來源:BarFileValidateTest.java

示例3: unZipToFolder

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * 把一個ZIP文件解壓到一個指定的目錄中
 * @param zipfilename ZIP文件抽象地址
 * @param outputdir 目錄絕對地址
 */
public static void unZipToFolder(String zipfilename, String outputdir) throws IOException {
    File zipfile = new File(zipfilename);
    if (zipfile.exists()) {
        outputdir = outputdir + File.separator;
        FileUtils.forceMkdir(new File(outputdir));

        ZipFile zf = new ZipFile(zipfile, "UTF-8");
        Enumeration zipArchiveEntrys = zf.getEntries();
        while (zipArchiveEntrys.hasMoreElements()) {
            ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) zipArchiveEntrys.nextElement();
            if (zipArchiveEntry.isDirectory()) {
                FileUtils.forceMkdir(new File(outputdir + zipArchiveEntry.getName() + File.separator));
            } else {
                IOUtils.copy(zf.getInputStream(zipArchiveEntry), FileUtils.openOutputStream(new File(outputdir + zipArchiveEntry.getName())));
            }
        }
    } else {
        throw new IOException("指定的解壓文件不存在:\t" + zipfilename);
    }
}
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:26,代碼來源:CompressExample.java

示例4: getHashesFromZipFile

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public List<String> getHashesFromZipFile(File file) throws IOException {
  List<String> hashes = new ArrayList<>();
  ZipFile zipFile = new ZipFile(file);

  byte[] buf = new byte[65536];
  Enumeration<?> entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) entries.nextElement();
    int n;
    InputStream is = zipFile.getInputStream(zipArchiveEntry);
    ZipArchiveInputStream zis = new ZipArchiveInputStream(is);

    if (zis.canReadEntryData(zipArchiveEntry)) {
      while ((n = is.read(buf)) != -1) {
        if (n > 0) {
          hashes.add(DigestUtils.md5Hex(buf));
        }
      }
    }
    zis.close();
  }

  return hashes;
}
 
開發者ID:sysunite,項目名稱:excel-microservice,代碼行數:25,代碼來源:ExcelWriteControllerTest.java

示例5: extractZipFile

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private static void extractZipFile(final File destination, final ZipFile zipFile) throws IOException {
    final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();

    while (entries.hasMoreElements()) {
        final ZipArchiveEntry entry = entries.nextElement();
        final File entryDestination = new File(destination, entry.getName());

        if (entry.isDirectory()) {
            entryDestination.mkdirs();
        } else {
            entryDestination.getParentFile().mkdirs();
            final InputStream in = zipFile.getInputStream(entry);
            try (final OutputStream out = new FileOutputStream(entryDestination)) {
                IOUtils.copy(in, out);
                IOUtils.closeQuietly(in);
            }
        }
    }
}
 
開發者ID:awslabs,項目名稱:aws-codepipeline-plugin-for-jenkins,代碼行數:20,代碼來源:ExtractionTools.java

示例6: makeTargetZipFile

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * Writes a modified version of zip_Source into target.
 *
 * @author S3460
 * @param zipSource the zip source
 * @param target the target
 * @return the zip file
 * @throws Exception the exception
 */
private ZipFile makeTargetZipFile(ZipFile zipSource, File target) throws Exception {
  ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(target));
  for (Enumeration<ZipArchiveEntry> enumer = zipSource.getEntries(); enumer.hasMoreElements();) {
    ZipArchiveEntry sourceEntry = enumer.nextElement();
    out.putArchiveEntry(new ZipArchiveEntry(sourceEntry.getName()));
    byte[] oldBytes = toBytes(zipSource, sourceEntry);
    byte[] newBytes = getRandomBytes();
    byte[] mixedBytes = mixBytes(oldBytes, newBytes);
    out.write(mixedBytes, 0, mixedBytes.length);
    out.flush();
    out.closeArchiveEntry();
  }
  out.putArchiveEntry(new ZipArchiveEntry("zipentry" + entryMaxSize + 1));
  byte[] bytes = getRandomBytes();
  out.write(bytes, 0, bytes.length);
  out.flush();
  out.closeArchiveEntry();
  out.putArchiveEntry(new ZipArchiveEntry("zipentry" + (entryMaxSize + 2)));
  out.closeArchiveEntry();
  out.flush();
  out.finish();
  out.close();
  return new ZipFile(targetFile);
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:34,代碼來源:JarDeltaJarPatcherTest.java

示例7: compareFiles

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * Compares the content of two zip files. The zip files are considered equal, if
 * the content of all zip entries is equal to the content of its corresponding entry
 * in the other zip file.
 *
 * @author S3460
 * @param zipSource the zip source
 * @param resultZip the result zip
 * @throws Exception the exception
 */
private void compareFiles(ZipFile zipSource, ZipFile resultZip) throws Exception {
  boolean rc = false;
  try {
    for (Enumeration<ZipArchiveEntry> enumer = zipSource.getEntries(); enumer.hasMoreElements();) {
      ZipArchiveEntry sourceEntry = enumer.nextElement();
      ZipArchiveEntry resultEntry = resultZip.getEntry(sourceEntry.getName());
      assertNotNull("Entry nicht generiert: " + sourceEntry.getName(), resultEntry);
      byte[] oldBytes = toBytes(zipSource, sourceEntry);
      byte[] newBytes = toBytes(resultZip, resultEntry);
      rc = equal(oldBytes, newBytes);
      assertTrue("bytes the same " + sourceEntry, rc);
    }
  } finally {
    zipSource.close();
    resultZip.close();
  }
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:28,代碼來源:JarDeltaJarPatcherTest.java

示例8: detectKmz

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private static MediaType detectKmz(ZipFile zip) {
    boolean kmlFound = false;

    Enumeration<ZipArchiveEntry> entries = zip.getEntries();
    while (entries.hasMoreElements()) {
        ZipArchiveEntry entry = entries.nextElement();
        String name = entry.getName();
        if (!entry.isDirectory()
                && name.indexOf('/') == -1 && name.indexOf('\\') == -1) {
            if (name.endsWith(".kml") && !kmlFound) {
                kmlFound = true;
            } else {
                return null;
            }
        }
    }

    if (kmlFound) {
        return MediaType.application("vnd.google-earth.kmz");
    } else {
        return null;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:24,代碼來源:ZipContainerDetector.java

示例9: detectIpa

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static MediaType detectIpa(ZipFile zip) {
    // Note - consider generalising this logic, if another format needs many regexp matching
    Set<Pattern> tmpPatterns = (Set<Pattern>)ipaEntryPatterns.clone();
    
    Enumeration<ZipArchiveEntry> entries = zip.getEntries();
    while (entries.hasMoreElements()) {
        ZipArchiveEntry entry = entries.nextElement();
        String name = entry.getName();
        
        Iterator<Pattern> ip = tmpPatterns.iterator();
        while (ip.hasNext()) {
            if (ip.next().matcher(name).matches()) {
                ip.remove();
            }
        }
        if (tmpPatterns.isEmpty()) {
            // We've found everything we need to find
            return MediaType.application("x-itunes-ipa");
        }
    }
    
    // If we get here, not all required entries were found
    return null;
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:26,代碼來源:ZipContainerDetector.java

示例10: testEmptyBaseDirRelativeDir

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testEmptyBaseDirRelativeDir() throws Exception {
    String aTargetFilename = "target/Z6-input.zip";
    ZipFilesTasklet aTasklet = new ZipFilesTasklet();
    aTasklet.setSourceBaseDirectory(new FileSystemResource(""));
    FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
    aSourceFactory.setPattern("file:src/test/resources/testFiles/input.csv");
    aTasklet.setSourceFactory(aSourceFactory );
    ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
    aDestinationFactory.setExpression(aTargetFilename);
    aTasklet.setDestinationFactory(aDestinationFactory );
    
    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(null, null));
    
    assertTrue(new File(aTargetFilename).exists());
    ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
    Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries();
    assertTrue(aEntries.hasMoreElements());
    assertEquals("src/test/resources/testFiles/input.csv", aEntries.nextElement().getName());
    assertFalse(aEntries.hasMoreElements());
    aZipFile.close();
}
 
開發者ID:acxio,項目名稱:AGIA,代碼行數:23,代碼來源:ZipFilesTaskletTest.java

示例11: readFirstZipEntry

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * Reads the first file entry in a zip file and returns it's contents
 * as uncompressed byte-array
 * @param zipFile the zip file to read from
 * @return the first file entry (uncompressed)
 * @throws IOException if there is an error accessing the zip file
 */
public static byte[] readFirstZipEntry(File zipFile) throws IOException {
    // open zip
    ZipFile zf = new ZipFile(zipFile);
    Enumeration<ZipArchiveEntry> entries = zf.getEntries();

    // read first entry to byte[]
    ZipArchiveEntry entry = entries.nextElement();
    InputStream is = zf.getInputStream(entry);
    byte[] raw = ByteStreams.toByteArray(is);

    // close all streams and return byte[]
    is.close();
    zf.close();
    return raw;
}
 
開發者ID:klamann,項目名稱:maps4cim,代碼行數:23,代碼來源:Compression.java

示例12: unzip

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public static void unzip(File zipFile, File destination)
        throws IOException {
    ZipFile zip = new ZipFile(zipFile);
    try {
        Enumeration<ZipArchiveEntry> e = zip.getEntries();
        while (e.hasMoreElements()) {
            ZipArchiveEntry entry = e.nextElement();
            File file = new File(destination, entry.getName());
            if (entry.isDirectory()) {
                file.mkdirs();
            } else {
                InputStream is = zip.getInputStream(entry);
                File parent = file.getParentFile();
                if (parent != null && parent.exists() == false) {
                    parent.mkdirs();
                }
                FileOutputStream os = new FileOutputStream(file);
                try {
                    IOUtils.copy(is, os);
                } finally {
                    os.close();
                    is.close();
                }
                file.setLastModified(entry.getTime());
                int mode = entry.getUnixMode();
                if ((mode & EXEC_MASK) != 0) {
                    if (!file.setExecutable(true)) {
                    }
                }
            }
        }
    } finally {
        ZipFile.closeQuietly(zip);
    }
}
 
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:36,代碼來源:MavenDownloader.java

示例13: unzipToTemporaryDirectory

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public static Path unzipToTemporaryDirectory(File file) throws IOException {
    ZipFile zipFile = new ZipFile(file);
    Enumeration<ZipArchiveEntry> zipEntries = zipFile.getEntries();
    Path tempDirectory = Files.createTempDirectory("temp");
    while (zipEntries.hasMoreElements()) {
        ZipArchiveEntry entry = zipEntries.nextElement();
        FileUtils.copyInputStreamToFile(zipFile.getInputStream(entry), new File(Paths.get(tempDirectory.toString(),"/" + entry.getName()).toString()));
    }

    zipFile.close();
    return tempDirectory;
}
 
開發者ID:FutureCitiesCatapult,項目名稱:TomboloDigitalConnector,代碼行數:13,代碼來源:ZipUtils.java

示例14: extractAll

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public static void extractAll(String zipFile, String extractDir) throws Exception {
	ZipFile unzipFile = new ZipFile(zipFile);
	try {
		File root = new File(extractDir);
		Enumeration<ZipArchiveEntry> fileHeaderList = unzipFile.getEntries();
		while(fileHeaderList.hasMoreElements()) {
			ZipArchiveEntry fileHeader = fileHeaderList.nextElement();
			if (fileHeader.isDirectory()) {
				//...
			} else if (!fileHeader.isUnixSymlink()) {
				File f = new File(root, fileHeader.getName());
				File dir = f.getParentFile();
				if (!dir.exists()) {
					dir.mkdirs();
				}
				FileOutputStream fout = new FileOutputStream(f);
				try {
					IOUtils.copy(unzipFile.getInputStream(fileHeader), fout);
				} finally {
					try {
						fout.close();
					} catch (Throwable e) {
					}
				}
				f.setLastModified(fileHeader.getLastModifiedDate().getTime());
			}
		}
	} finally {
		ZipFile.closeQuietly(unzipFile);
	}
}
 
開發者ID:BeckYang,項目名稱:TeamFileList,代碼行數:32,代碼來源:ZipUtil.java

示例15: decompressZip

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public void decompressZip(File zipFile, String dir) throws IOException {
	ZipFile zf = new ZipFile(zipFile);
	try {
		for (Enumeration<ZipArchiveEntry> entries = zf.getEntries(); entries
				.hasMoreElements();) {
			ZipArchiveEntry ze = entries.nextElement();
			// 不存在則創建目標文件夾。
			File targetFile = new File(dir, ze.getName());
			// 遇到根目錄時跳過。
			if (ze.getName().lastIndexOf("/") == (ze.getName().length() - 1)) {
				continue;
			}
			// 如果文件夾不存在,創建文件夾。
			if (!targetFile.getParentFile().exists()) {
				targetFile.getParentFile().mkdirs();
			}

			InputStream i = zf.getInputStream(ze);
			OutputStream o = null;
			try {
				o = new FileOutputStream(targetFile);
				IOUtils.copy(i, o);
			} finally {
				if (i != null) {
					i.close();
				}
				if (o != null) {
					o.close();
				}
			}
		}
	} finally {
		zf.close();
	}
}
 
開發者ID:hoozheng,項目名稱:AndroidRobot,代碼行數:36,代碼來源:ZipUtil.java


注:本文中的org.apache.commons.compress.archivers.zip.ZipFile.getEntries方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。