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


Java ZipFile類代碼示例

本文整理匯總了Java中java.util.zip.ZipFile的典型用法代碼示例。如果您正苦於以下問題:Java ZipFile類的具體用法?Java ZipFile怎麽用?Java ZipFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: RandomAccessLogReader

import java.util.zip.ZipFile; //導入依賴的package包/類
/**
 * create me based on a (potentially zipped) file
 * 
 * @param file
 * @throws Exception
 */
public RandomAccessLogReader(File logFile) throws Exception {
  if (logFile.getName().endsWith(".zip")) {
    File unzipped = new File(logFile.getParentFile(), "unzipped");
    zipFile = new ZipFile(logFile);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    if (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();
      if (!entry.isDirectory()) {
        if (!unzipped.isDirectory()) {
          unzipped.mkdir();
        }
        elmLogFile = new File(unzipped, entry.getName());
        InputStream in = zipFile.getInputStream(entry);
        OutputStream out = new FileOutputStream(elmLogFile);
        IOUtils.copy(in, out);
        IOUtils.closeQuietly(in);
        out.close();
      }
    }
  } else {
    elmLogFile = logFile;
  }
}
 
開發者ID:BITPlan,項目名稱:can4eve,代碼行數:30,代碼來源:RandomAccessLogReader.java

示例2: loadModuleProperties

import java.util.zip.ZipFile; //導入依賴的package包/類
private Properties loadModuleProperties(String name, File jarFile) {
    try {
        ZipFile zipFile = new ZipFile(jarFile);
        try {
            final String entryName = name + "-classpath.properties";
            ZipEntry entry = zipFile.getEntry(entryName);
            if (entry == null) {
                throw new IllegalStateException("Did not find " + entryName + " in " + jarFile.getAbsolutePath());
            }
            return GUtil.loadProperties(zipFile.getInputStream(entry));
        } finally {
            zipFile.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:18,代碼來源:DefaultModuleRegistry.java

示例3: addFiles

import java.util.zip.ZipFile; //導入依賴的package包/類
/**
 * @param pack The scriptFiles to set.
 */
private void addFiles(ZipFile pack)
{
	for (Enumeration<? extends ZipEntry> e = pack.entries(); e.hasMoreElements();)
	{
		ZipEntry entry = e.nextElement();
		if (entry.getName().endsWith(".xml"))
		{
			try
			{
				ScriptDocument newScript = new ScriptDocument(entry.getName(), pack.getInputStream(entry));
				_scriptFiles.add(newScript);
			}
			catch (IOException e1)
			{
				e1.printStackTrace();
			}
		}
		else if (!entry.isDirectory())
		{
			_otherFiles.add(entry.getName());
		}
	}
}
 
開發者ID:L2jBrasil,項目名稱:L2jBrasil,代碼行數:27,代碼來源:ScriptPackage.java

示例4: unZip

import java.util.zip.ZipFile; //導入依賴的package包/類
public MasterTemplateLoader unZip(String dest)
{
    try{

        ZipFile zipFile = new ZipFile(this.dest);
        ZipEntry z;
        Enumeration<? extends ZipEntry> entryEnumeration = zipFile.entries();
        while (entryEnumeration.hasMoreElements())
        {
            z = entryEnumeration.nextElement();
            extractEntry(zipFile, z, dest);
        }
        new File(this.dest).delete();
    }catch (Exception ex)
    {
        ex.printStackTrace();
    }
    return this;
}
 
開發者ID:Dytanic,項目名稱:CloudNet,代碼行數:20,代碼來源:MasterTemplateLoader.java

示例5: getABIsFromApk

import java.util.zip.ZipFile; //導入依賴的package包/類
private static Set<String> getABIsFromApk(String apk) {
	try {
		ZipFile apkFile = new ZipFile(apk);
		Enumeration<? extends ZipEntry> entries = apkFile.entries();
		Set<String> supportedABIs = new HashSet<String>();
		while (entries.hasMoreElements()) {
			ZipEntry entry = entries.nextElement();
			String name = entry.getName();
			if (name.contains("../")) {
				continue;
			}
			if (name.startsWith("lib/") && !entry.isDirectory() && name.endsWith(".so")) {
				String supportedAbi = name.substring(name.indexOf("/") + 1, name.lastIndexOf("/"));
				supportedABIs.add(supportedAbi);
			}
		}
		return supportedABIs;
	} catch (Exception e) {
		e.printStackTrace();
	}

	return null;
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:24,代碼來源:NativeLibraryHelperCompat.java

示例6: findNBRoot

import java.util.zip.ZipFile; //導入依賴的package包/類
private static String findNBRoot(final ZipFile nbSrcZip) {
    String nbRoot = null;
    for (Enumeration<? extends ZipEntry> en = nbSrcZip.entries(); en.hasMoreElements(); ) {
        ZipEntry entry = (ZipEntry) en.nextElement();
        if (!entry.isDirectory()) {
            continue;
        }
        String name = entry.getName();
        if (!name.equals(NBBUILD_ENTRY) &&
                !(name.endsWith(NBBUILD_ENTRY) && name.substring(name.indexOf('/') + 1).equals(NBBUILD_ENTRY))) {
            continue;
        }
        ZipEntry xmlEntry = nbSrcZip.getEntry(name + "nbproject/project.xml"); // NOI18N
        if (xmlEntry != null) {
            nbRoot = name.substring(0, name.length() - NBBUILD_ENTRY.length());
            break;
        }
    }
    return nbRoot;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:GlobalSourceForBinaryImpl.java

示例7: apkPackageName

import java.util.zip.ZipFile; //導入依賴的package包/類
@Nullable
public ManifestData apkPackageName(File apkFile) {
    if (apkFile == null) {
        return null;
    }
    try {
        ZipFile zip = new ZipFile(apkFile);
        ZipEntry mft = zip.getEntry(AndroidConstants.ANDROID_MANIFEST_XML);

        ApkUtils decompresser = new ApkUtils();
        String xml = decompresser.decompressXML(ByteStreams.toByteArray(zip.getInputStream(mft)));
        ManifestData manifest = AndroidProjects.parseProjectManifest(new ByteArrayInputStream(xml.getBytes()));
        return manifest;
    } catch (IOException ex) {
        LOG.log(Level.INFO, "cannot get package name from apk file " + apkFile, ex);
        return null;
    }

}
 
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:20,代碼來源:ApkUtils.java

示例8: reload

import java.util.zip.ZipFile; //導入依賴的package包/類
public void reload() throws IOException {
    mappings.clear();
    ZipFile zipfile = new ZipFile(zip);

    try {
        for (MappingType type : MappingType.values()) {
            if (type.getCsvName() != null) {
                List<String> lines;
                lines = IOUtils.readLines(zipfile.getInputStream(zipfile.getEntry(type.getCsvName() + ".csv")), Charsets.UTF_8);

                lines.remove(0); // Remove header line

                for (String line : lines) {
                    String[] info = line.split(",", -1);
                    String comment = info.length > 3 ? Joiner.on(',').join(ArrayUtils.subarray(info, 3, info.length)) : "";
                    IMapping mapping = new IMapping.Impl(type, info[0], info[1], comment, Side.values()[Integer.valueOf(info[2])]);
                    mappings.put(type, mapping);
                }
            }
        }
    } finally {
        zipfile.close();
    }
}
 
開發者ID:tterrag1098,項目名稱:MCBot,代碼行數:25,代碼來源:MappingDatabase.java

示例9: getCrc

import java.util.zip.ZipFile; //導入依賴的package包/類
private long getCrc(ZipFile file, ZipEntry entry) throws IOException {
  long crc = -1;
  if (entry != null) {
    crc = entry.getCrc();
    if (crc < 0) {
      CRC32 checksum = new CRC32();

      final InputStream in = file.getInputStream(entry);
      try {
        final byte[] buffer = new byte[1024];
        int count;
        while ((count = in.read(buffer)) >= 0) {
          checksum.update(buffer, 0, count);
        }
        in.close();
        crc = checksum.getValue();
      }
      finally {
        IOUtils.closeQuietly(in);
      }
    }
  }
  return crc;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:25,代碼來源:ZipUpdater.java

示例10: testDate

import java.util.zip.ZipFile; //導入依賴的package包/類
private static void testDate(byte[] data, int date, LocalDate expected) throws IOException {
    // set the datetime
    int endpos = data.length - ENDHDR;
    int cenpos = u16(data, endpos + ENDOFF);
    int locpos = u16(data, cenpos + CENOFF);
    writeU32(data, cenpos + CENTIM, date);
    writeU32(data, locpos + LOCTIM, date);

    // ensure that the archive is still readable, and the date is 1979-11-30
    Path path = Files.createTempFile("out", ".zip");
    try (OutputStream os = Files.newOutputStream(path)) {
        os.write(data);
    }
    try (ZipFile zf = new ZipFile(path.toFile())) {
        ZipEntry ze = zf.entries().nextElement();
        Instant actualInstant = ze.getLastModifiedTime().toInstant();
        Instant expectedInstant =
                expected.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
        if (!actualInstant.equals(expectedInstant)) {
            throw new AssertionError(
                    String.format("actual: %s, expected: %s", actualInstant, expectedInstant));
        }
    } finally {
        Files.delete(path);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ZeroDate.java

示例11: init

import java.util.zip.ZipFile; //導入依賴的package包/類
public boolean init(File path) {
	_path = path;

	try {
		File parentFile = path.getParentFile();
		_classLoader = new DexClassLoader(_path.getAbsolutePath(), parentFile.getAbsolutePath(), null, getClass().getClassLoader());

		_pluginPackage = new ZipFile(_path);
		ZipEntry entry = _pluginPackage.getEntry("plugin.txt");
		BufferedReader reader = new BufferedReader(new InputStreamReader(_pluginPackage.getInputStream(entry)));
		String pluginClassName = reader.readLine();
		reader.close();

		Class<?> pluginClass = _classLoader.loadClass(pluginClassName);
		_plugin = (XulPlugin) pluginClass.newInstance();
		return true;
	} catch (Throwable e) {
		e.printStackTrace();
	}
	return false;
}
 
開發者ID:starcor-company,項目名稱:starcor.xul,代碼行數:22,代碼來源:XulPluginManager.java

示例12: getResourceAsStream

import java.util.zip.ZipFile; //導入依賴的package包/類
public InputStream getResourceAsStream(String resName)
{
    try
    {
        if (this.packZipFile == null)
        {
            this.packZipFile = new ZipFile(this.packFile);
        }

        String s = StrUtils.removePrefix(resName, "/");
        ZipEntry zipentry = this.packZipFile.getEntry(s);
        return zipentry == null ? null : this.packZipFile.getInputStream(zipentry);
    }
    catch (Exception var4)
    {
        return null;
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:19,代碼來源:ShaderPackZip.java

示例13: loadAndValidate

import java.util.zip.ZipFile; //導入依賴的package包/類
/**
 * Load zip entries from package to HashMap and check if meta-file is present
 * @param path path to package
 * @throws Exception thrown when meta-file is not present in package
 */
private static void loadAndValidate(String path) throws Exception {
    boolean found = false;
    zip = new ZipFile(path);
    Enumeration<? extends ZipEntry> entries = zip.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();

        if (entry.getName().equals("meta-file") && !entry.isDirectory()) {
            found = true;
        }

        GameLoader.entries.put(entry.getName(), entry);
    }

    if (!found) {
        throw new Exception(String.format("'%s' is not valid game!", path));
    }
}
 
開發者ID:achjaj,項目名稱:Tengine,代碼行數:25,代碼來源:GameLoader.java

示例14: unzipFile

import java.util.zip.ZipFile; //導入依賴的package包/類
private void unzipFile(Path zipPath, Path targetDirectory) throws IOException {
  try (ZipFile zipFile = new ZipFile(zipPath.toFile())) {
    for (Enumeration<? extends ZipEntry> entries = zipFile.entries();
        entries.hasMoreElements(); ) {
      ZipEntry entry = entries.nextElement();
      Path targetFile = targetDirectory.resolve(entry.getName());
      if (entry.isDirectory()) {
        Files.createDirectories(targetFile);
      } else {
        Files.createDirectories(targetFile.getParent());
        try (InputStream in = zipFile.getInputStream(entry)) {
          Files.copy(in, targetFile);
        }
      }
    }
  }
}
 
開發者ID:google,項目名稱:ios-device-control,代碼行數:18,代碼來源:SimulatorDeviceImpl.java

示例15: uncompress

import java.util.zip.ZipFile; //導入依賴的package包/類
public static boolean uncompress(String zipFilePath, String descDir) throws IOException {
    //如果指定路徑的壓縮文件不存在,會拋出 IO EXCEPTION
    ZipFile zipFile = new ZipFile(zipFilePath);
    File pathFile = new File(descDir);
    if(!pathFile.exists()){
        pathFile.mkdirs();
    }
    Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
    while (zipEntries.hasMoreElements()) {
        ZipEntry zipEntry = zipEntries.nextElement();
        OutputStream outputStream = new FileOutputStream("D:/testZip/lala" + "/" + new File(zipEntry.getName()));
        InputStream inputStream = zipFile.getInputStream(zipEntry);
        int len = inputStream.read();
        while (len != -1) {
            outputStream.write(len);
            len = inputStream.read();
        }
        inputStream.close();
        outputStream.close();
    }
    return true;
}
 
開發者ID:Topview-us,項目名稱:school-website,代碼行數:23,代碼來源:OperateFileUtils.java


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