当前位置: 首页>>代码示例>>Java>>正文


Java ZipFile.entries方法代码示例

本文整理汇总了Java中java.util.zip.ZipFile.entries方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.entries方法的具体用法?Java ZipFile.entries怎么用?Java ZipFile.entries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.ZipFile的用法示例。


在下文中一共展示了ZipFile.entries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readClass

import java.util.zip.ZipFile; //导入方法依赖的package包/类
@Override
public byte[] readClass(String className) throws IOException {
    byte[] ret = null;
    ZipFile zf = new ZipFile(absPath);
    for (Enumeration<? extends java.util.zip.ZipEntry> ez = zf.entries(); ez.hasMoreElements();) {
        java.util.zip.ZipEntry ze = ez.nextElement();
        if (className.equals(ze.toString())) {
            ret = new byte[(int)ze.getSize()];
            
            InputStream is = zf.getInputStream(ze);
            int len = ret.length;
            int offset = 0;
            while (offset < len) {
                offset += is.read(ret, offset, len-offset);  
            }
            return ret;
        }
    }

    return ret;
}
 
开发者ID:lxyscls,项目名称:jvmjava,代码行数:22,代码来源:ZipEntry.java

示例2: copyExistingFiles

import java.util.zip.ZipFile; //导入方法依赖的package包/类
private void copyExistingFiles(ZipFile inputFile, ZipOutputStream outputFile) throws IOException {
    // First, copy the contents from the existing outFile:
    Enumeration<? extends ZipEntry> entries = inputFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = new ZipEntry(entries.nextElement());

        // We can't reuse the compressed size because it depends on compression sizes.
        entry.setCompressedSize(-1);
        outputFile.putNextEntry(entry);

        // No need to create directory entries in the final apk
        if (! entry.isDirectory()) {
            BrutIO.copy(inputFile, outputFile, entry);
        }

        outputFile.closeEntry();
    }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:19,代码来源:Androlib.java

示例3: 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

示例4: 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

示例5: OldSimulationArchive

import java.util.zip.ZipFile; //导入方法依赖的package包/类
public OldSimulationArchive(File file) throws IOException {
    if (file == null) {
        throw new IllegalArgumentException("file is null.");
    }
    if (!file.exists()) {
        throw new IllegalArgumentException("file not exist: [" + file.getAbsolutePath() + "]");
    }
    this.archiveFile = file;
    ZipFile zip = new ZipFile(file);

    Enumeration<?> entries = zip.entries();
    for (; entries.hasMoreElements(); ) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        log.debug("found entry: " + entry.getName());
        this.entryNames.add(entry.getName());
    }

    for (String entryName : entryNames) {
        if (entryName.matches("[0-9.]+\\.pdu")) {
            String targetId = entryName.replace(".pdu", "");
            this.targetList.add(targetId);
            log.debug("* " + targetId);
        }
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:26,代码来源:OldSimulationArchive.java

示例6: copyZipFile

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/** Copy source zip file to target userdir obeying include/exclude patterns.
 * @throws IOException if copying fails
 */
private void copyZipFile() throws IOException {
    // Open the ZIP file
    ZipFile zipFile = new ZipFile(source);
    try {
        // Enumerate each entry
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = entries.nextElement();
            if (!zipEntry.isDirectory()) {
                copyFile(zipEntry.getName());
            }
        }
    } finally {
        if (zipFile != null) {
            zipFile.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:OptionsExportModel.java

示例7: 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

示例8: process

import java.util.zip.ZipFile; //导入方法依赖的package包/类
private static void process(File jarFile, File outputFile, String message) throws Throwable {
    ZipFile zipFile = new ZipFile(jarFile);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
    try {
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
                try (InputStream in = zipFile.getInputStream(entry)) {
                    ClassReader cr = new ClassReader(in);
                    ClassNode classNode = new ClassNode();
                    cr.accept(classNode, 0);

                    messageInjector(classNode, message);

                    ClassWriter cw = new ClassWriter(0);
                    classNode.accept(cw);
                    ZipEntry newEntry = new ZipEntry(entry.getName());
                    newEntry.setTime(System.currentTimeMillis());
                    out.putNextEntry(newEntry);
                    writeToFile(out, new ByteArrayInputStream(cw.toByteArray()));
                }
            } else {
                entry.setTime(System.currentTimeMillis());
                out.putNextEntry(entry);
                writeToFile(out, zipFile.getInputStream(entry));
            }
        }
    } finally {
        zipFile.close();
        out.close();
        if (!messagegotinjected) {
            // throw new IllegalStateException("Could not find Bukkit onEnable or onLoad method.");
            throw new IllegalStateException("Could not find Bukkit onEnable method.");
        }
    }
}
 
开发者ID:ItzSomebody,项目名称:BukkitPlugin-Message-Injector,代码行数:38,代码来源:Injector.java

示例9: upZipSelectedFile

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
 * 解压文件名包含传入文字的文件
 *
 * @param zipFile 压缩文件
 * @param folderPath 目标文件夹
 * @param nameContains 传入的文件匹配名
 * @throws ZipException 压缩格式有误时抛出
 * @throws IOException IO错误时抛出
 */
public static ArrayList<File> upZipSelectedFile(File zipFile, String folderPath,
        String nameContains) throws ZipException, IOException {
    ArrayList<File> fileList = new ArrayList<File>();
 
    File desDir = new File(folderPath);
    if (!desDir.exists()) {
        desDir.mkdir();
    }
 
    ZipFile zf = new ZipFile(zipFile);
    for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
        ZipEntry entry = ((ZipEntry)entries.nextElement());
        if (entry.getName().contains(nameContains)) {
            InputStream in = zf.getInputStream(entry);
            String str = folderPath + File.separator + entry.getName();
            str = new String(str.getBytes("utf-8"), "gbk");
            // str.getBytes("GB2312"),"8859_1" 输出
            // str.getBytes("8859_1"),"GB2312" 输入
            File desFile = new File(str);
            if (!desFile.exists()) {
                File fileParentDir = desFile.getParentFile();
                if (!fileParentDir.exists()) {
                    fileParentDir.mkdirs();
                }
                desFile.createNewFile();
            }
            OutputStream out = new FileOutputStream(desFile);
            byte buffer[] = new byte[BUFF_SIZE];
            int realLength;
            while ((realLength = in.read(buffer)) > 0) {
                out.write(buffer, 0, realLength);
            }
            in.close();
            out.close();
            fileList.add(desFile);
        }
    }
    return fileList;
}
 
开发者ID:BaoBaoJianqiang,项目名称:HybridForAndroid,代码行数:49,代码来源:ZipUtils.java

示例10: collectFilesZIP

import java.util.zip.ZipFile; //导入方法依赖的package包/类
private static String[] collectFilesZIP(File p_collectFilesZIP_0_, String p_collectFilesZIP_1_, String p_collectFilesZIP_2_)
{
    List list = new ArrayList();
    String s = "assets/minecraft/";

    try
    {
        ZipFile zipfile = new ZipFile(p_collectFilesZIP_0_);
        Enumeration enumeration = zipfile.entries();

        while (enumeration.hasMoreElements())
        {
            ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
            String s1 = zipentry.getName();

            if (s1.startsWith(s))
            {
                s1 = s1.substring(s.length());

                if (s1.startsWith(p_collectFilesZIP_1_) && s1.endsWith(p_collectFilesZIP_2_))
                {
                    list.add(s1);
                }
            }
        }

        zipfile.close();
        String[] astring = (String[])((String[])list.toArray(new String[list.size()]));
        return astring;
    }
    catch (IOException ioexception)
    {
        ioexception.printStackTrace();
        return new String[0];
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:37,代码来源:ConnectedTextures.java

示例11: getLibFiles

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
 * getLibFiles
 *
 * @param zipFile   zipFile
 * @param targetDir targetDir
 */
private final static Map<String, Map<String, String>> getLibFiles(String zipFile, String targetDir) {
    Map<String, Map<String, String>> entryFiles = new HashMap<String, Map<String, String>>();
    try {
        ZipFile zf = new ZipFile(zipFile);
        Enumeration<?> entries = zf.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            if (entry.getName().startsWith("lib/")) {
                String[] entrys = entry.getName().split("/");
                if (entrys.length >= 3) {
                    String abi = entrys[1];
                    String targetEntry = entrys[entrys.length - 1];
                    String libraryEntry = targetDir + "/" + targetEntry;
                    if (entryFiles.containsKey(abi)) {
                        entryFiles.get(abi).put(entry.getName(), libraryEntry);
                    } else {
                        Map<String, String> libs = new HashMap<String, String>();
                        libs.put(entry.getName(), libraryEntry);
                        entryFiles.put(abi, libs);
                    }
                }
            }
        }
        zf.close();
    } catch (Exception e) {
    }
    return entryFiles;
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:35,代码来源:ApkNative.java

示例12: upZipSelectedFile

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
 * 解压文件名包含传入文字的文件
 *
 * @param zipFile      压缩文件
 * @param folderPath   目标文件夹
 * @param nameContains 传入的文件匹配名
 * @throws ZipException 压缩格式有误时抛出
 * @throws IOException  IO错误时抛出
 */
public static ArrayList<File> upZipSelectedFile(File zipFile, String folderPath,
                                                String nameContains) throws ZipException, IOException {
    ArrayList<File> fileList = new ArrayList<File>();

    File desDir = new File(folderPath);
    if (!desDir.exists()) {
        desDir.mkdir();
    }
    ZipFile zf = new ZipFile(zipFile);
    for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements(); ) {
        ZipEntry entry = ((ZipEntry) entries.nextElement());
        if (entry.getName().contains(nameContains)) {
            InputStream in = zf.getInputStream(entry);
            String str = folderPath + File.separator + entry.getName();
            str = new String(str.getBytes("8859_1"), "GB2312");
            // str.getBytes("GB2312"),"8859_1" 输出
            // str.getBytes("8859_1"),"GB2312" 输入
            File desFile = new File(str);
            if (!desFile.exists()) {
                File fileParentDir = desFile.getParentFile();
                if (!fileParentDir.exists()) {
                    fileParentDir.mkdirs();
                }
                desFile.createNewFile();
            }
            OutputStream out = new FileOutputStream(desFile);
            byte buffer[] = new byte[BUFF_SIZE];
            int realLength;
            while ((realLength = in.read(buffer)) > 0) {
                out.write(buffer, 0, realLength);
            }
            in.close();
            out.close();
            fileList.add(desFile);
        }
    }
    return fileList;
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:48,代码来源:ZipUtils.java

示例13: upZipFile

import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static void upZipFile(File zipFile, String folderPath) throws ZipException, IOException {
    File desDir = new File(folderPath);
    if (!desDir.exists()) {
        desDir.mkdirs();
    }
    ZipFile zf = new ZipFile(zipFile);
    Enumeration<?> entries = zf.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        InputStream in = zf.getInputStream(entry);
        File desFile = new File(new String(new StringBuilder(String.valueOf(folderPath)).append(File.separator).append(entry.getName()).toString().getBytes("8859_1"), "GB2312"));
        if (!desFile.exists()) {
            File fileParentDir = desFile.getParentFile();
            if (!fileParentDir.exists()) {
                fileParentDir.mkdirs();
            }
            desFile.createNewFile();
        }
        OutputStream out = new FileOutputStream(desFile);
        byte[] buffer = new byte[1048576];
        while (true) {
            int realLength = in.read(buffer);
            if (realLength <= 0) {
                break;
            }
            out.write(buffer, 0, realLength);
        }
        in.close();
        out.close();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:32,代码来源:ZipUtils.java

示例14: process

import java.util.zip.ZipFile; //导入方法依赖的package包/类
private static void process(File jarFile, File outputFile) throws Throwable {
    ZipFile zipFile = new ZipFile(jarFile);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
    try {
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
                try (InputStream in = zipFile.getInputStream(entry)) {
                    ClassReader cr = new ClassReader(in);
                    ClassNode classNode = new ClassNode();
                    cr.accept(classNode, 0);

                    removeAttr(classNode);

                    ClassWriter cw = new ClassWriter(0);
                    classNode.accept(cw);
                    ZipEntry newEntry = new ZipEntry(entry.getName());
                    newEntry.setTime(System.currentTimeMillis());
                    out.putNextEntry(newEntry);
                    writeToFile(out, new ByteArrayInputStream(cw.toByteArray()));
                }
            } else {
                entry.setTime(System.currentTimeMillis());
                out.putNextEntry(entry);
                writeToFile(out, zipFile.getInputStream(entry));
            }
        }
    } finally {
        zipFile.close();
        out.close();
    }
}
 
开发者ID:ItzSomebody,项目名称:Spigot-Attribute-Remover,代码行数:34,代码来源:Remover.java

示例15: upZipFile

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
 * 解压缩一个文件
 *
 * @param zipFile    压缩文件
 * @param folderPath 解压缩的目标目录
 * @throws IOException 当解压缩过程出错时抛出
 */
public static void upZipFile(File zipFile, String folderPath) throws ZipException, IOException {
    File desDir = new File(folderPath);
    if (!desDir.exists()) {
        desDir.mkdirs();
    }
    ZipFile zf = new ZipFile(zipFile);
    for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements(); ) {
        ZipEntry entry = ((ZipEntry) entries.nextElement());
        InputStream in = zf.getInputStream(entry);
        String str = folderPath + File.separator + entry.getName();
        str = new String(str.getBytes("8859_1"), "GB2312");
        File desFile = new File(str);
        if (!desFile.exists()) {
            File fileParentDir = desFile.getParentFile();
            if (!fileParentDir.exists()) {
                fileParentDir.mkdirs();
            }
            desFile.createNewFile();
        }
        OutputStream out = new FileOutputStream(desFile);
        byte buffer[] = new byte[BUFF_SIZE];
        int realLength;
        while ((realLength = in.read(buffer)) > 0) {
            out.write(buffer, 0, realLength);
        }
        in.close();
        out.close();
    }
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:37,代码来源:ZipUtils.java


注:本文中的java.util.zip.ZipFile.entries方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。