当前位置: 首页>>代码示例>>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;未经允许,请勿转载。