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


Java ZipFile.getEntry方法代码示例

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


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

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

示例2: Dex

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
 * Creates a new dex buffer from the dex file {@code file}.
 */
public Dex(File file) throws IOException{
    if (FileUtils.hasArchiveSuffix(file.getName())) {
        ZipFile zipFile = new ZipFile(file);
        ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
        if (entry != null) {
            loadFrom(zipFile.getInputStream(entry));
            zipFile.close();
        } else {
            throw new DexException2("Expected " + DexFormat.DEX_IN_JAR_NAME + " in " + file);
        }
    } else if (file.getName().endsWith(".dex")) {
        loadFrom(new FileInputStream(file));
    } else {
        throw new DexException2("unknown output extension: " + file);
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:20,代码来源:Dex.java

示例3: Dex

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
 * Creates a new dex buffer from the dex file {@code file}.
 */
public Dex(File file) throws IOException {
    if (FileUtils.hasArchiveSuffix(file.getName())) {
        ZipFile zipFile = new ZipFile(file);
        ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
        if (entry != null) {
            loadFrom(zipFile.getInputStream(entry));
            zipFile.close();
        } else {
            throw new DexException("Expected " + DexFormat.DEX_IN_JAR_NAME + " in " + file);
        }
    } else if (file.getName().endsWith(".dex")) {
        loadFrom(new FileInputStream(file));
    } else {
        throw new DexException("unknown output extension: " + file);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:Dex.java

示例4: getInputStreamByName

import java.util.zip.ZipFile; //导入方法依赖的package包/类
protected InputStream getInputStreamByName(String name) throws IOException
{
    ZipFile zipfile = this.getResourcePackZipFile();
    ZipEntry zipentry = zipfile.getEntry(name);

    if (zipentry == null)
    {
        throw new ResourcePackFileNotFoundException(this.resourcePackFile, name);
    }
    else
    {
        return zipfile.getInputStream(zipentry);
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:15,代码来源:FileResourcePack.java

示例5: findResource

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
 * Finds a resource. This method is called by {@code getResource()} after
 * the parent ClassLoader has failed to find a loaded resource of the same
 * name.
 *
 * @param name The name of the resource to find
 * @return the location of the resource as a URL, or {@code null} if the
 * resource is not found.
 */
@Override
protected URL findResource(String name) {
    ensureInit();

    int length = mFiles.length;

    for (int i = 0; i < length; i++) {
        File pathFile = mFiles[i];
        ZipFile zip = mZips[i];

        if (zip.getEntry(name) != null) {
            if (VERBOSE_DEBUG)
                System.out.println("  found " + name + " in " + pathFile);
            try {
                // File.toURL() is compliant with RFC 1738 in always
                // creating absolute path names. If we construct the
                // URL by concatenating strings, we might end up with
                // illegal URLs for relative names.
                return new URL("jar:" + pathFile.toURL() + "!/" + name);
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }
    }

    if (VERBOSE_DEBUG)
        System.out.println("  resource " + name + " not found");

    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:40,代码来源:DexClassLoader.java

示例6: getBuildDateAsString

import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
 * INTERNAL method that returns the build date of the current APK as a string, or null if unable to determine it.
 *
 * @param context    A valid context. Must not be null.
 * @param dateFormat DateFormat to use to convert from Date to String
 * @return The formatted date, or "Unknown" if unable to determine it.
 */
private static String getBuildDateAsString(Context context, DateFormat dateFormat) {
    String buildDate;
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
        ZipFile zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("classes.dex");
        long time = ze.getTime();
        buildDate = dateFormat.format(new Date(time));
        zf.close();
    } catch (Exception e) {
        buildDate = "Unknown";
    }
    return buildDate;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:22,代码来源:RCrashHandler.java

示例7: getSize

import java.util.zip.ZipFile; //导入方法依赖的package包/类
@Override
protected long getSize () throws IOException {
    ZipFile zf = new ZipFile (archiveFile);
    try {
        ZipEntry ze = zf.getEntry(this.resName);
        return ze == null ? 0L : ze.getSize();
    } finally {
        zf.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:FileObjects.java

示例8: getInputStream

import java.util.zip.ZipFile; //导入方法依赖的package包/类
@Override
public InputStream getInputStream() throws IOException {
    final ZipFile z = new ZipFile(getZipfile(), ZipFile.OPEN_READ);
    ZipEntry ze = z.getEntry(super.getName());
    if (ze == null) {
        z.close();
        throw new BuildException("no entry " + getName() + " in "
                                 + getArchive());
    }
    return z.getInputStream(ze);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:LayerIndex.java

示例9: contains

import java.util.zip.ZipFile; //导入方法依赖的package包/类
static boolean contains(File jarFile, String entryName)
    throws IOException {
    ZipFile zf = new ZipFile(jarFile);
    if ( zf != null ) {
        boolean result = zf.getEntry(entryName) != null;
        zf.close();
        return result;
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:MetaInf.java

示例10: performExtractions

import java.util.zip.ZipFile; //导入方法依赖的package包/类
private static List<File> performExtractions(File sourceApk, File dexDir) throws IOException {
    String extractedFilePrefix = sourceApk.getName() + EXTRACTED_NAME_EXT;
    prepareDexDir(dexDir, extractedFilePrefix);
    List<File> files = new ArrayList();
    ZipFile apk = new ZipFile(sourceApk);
    int secondaryNumber = 2;
    try {
        ZipEntry dexFile = apk.getEntry(DEX_PREFIX + 2 + ".dex");
        while (dexFile != null) {
            File extractedFile = new File(dexDir, extractedFilePrefix + secondaryNumber + EXTRACTED_SUFFIX);
            files.add(extractedFile);
            Log.i(TAG, "Extraction is needed for file " + extractedFile);
            int numAttempts = 0;
            boolean isExtractionSuccessful = false;
            while (numAttempts < 3 && !isExtractionSuccessful) {
                numAttempts++;
                extract(apk, dexFile, extractedFile, extractedFilePrefix);
                isExtractionSuccessful = verifyZipFile(extractedFile);
                Log.i(TAG, "Extraction " + (isExtractionSuccessful ? "success" : "failed") + " - length " + extractedFile.getAbsolutePath() + ": " + extractedFile.length());
                if (!isExtractionSuccessful) {
                    extractedFile.delete();
                    if (extractedFile.exists()) {
                        Log.w(TAG, "Failed to delete corrupted secondary dex '" + extractedFile.getPath() + "'");
                    }
                }
            }
            if (isExtractionSuccessful) {
                secondaryNumber++;
                dexFile = apk.getEntry(DEX_PREFIX + secondaryNumber + ".dex");
            } else {
                throw new IOException("Could not create zip file " + extractedFile.getAbsolutePath() + " for secondary dex (" + secondaryNumber + SocializeConstants.OP_CLOSE_PAREN);
            }
        }
        return files;
    } finally {
        try {
            apk.close();
        } catch (IOException e) {
            Log.w(TAG, "Failed to close resource", e);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:43,代码来源:MultiDexExtractor.java

示例11: ArchiveFileHandle

import java.util.zip.ZipFile; //导入方法依赖的package包/类
public ArchiveFileHandle(ZipFile archive, String fileName) {
    super(fileName.replace('\\', '/'), FileType.Classpath);
    this.archive = archive;
    this.archiveEntry = archive.getEntry(fileName.replace('\\', '/'));
}
 
开发者ID:justinmarentette11,项目名称:Tower-Defense-Galaxy,代码行数:6,代码来源:ArchiveFileHandle.java

示例12: getZipEntry

import java.util.zip.ZipFile; //导入方法依赖的package包/类
ZipEntry getZipEntry(ZipFile zip) {
    return zip.getEntry(path);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:RelativePath.java

示例13: unpack

import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static void unpack(File zipfile) {
    try {
        ZipFile zip = new ZipFile(zipfile);
        ZipEntry info = zip.getEntry("__PROJECT_INFO__");
        BufferedReader in = new BufferedReader(new InputStreamReader(zip.getInputStream(info), "UTF-8"));
        String pId = in.readLine();
        String pTitle = in.readLine();
        String pStartD = in.readLine();
        String pEndD = in.readLine();
        in.close();
        if (ProjectManager.getProject(pId) != null) {
            int n =
                JOptionPane.showConfirmDialog(
                    App.getFrame(),
                    Local.getString("This project is already exists and will be replaced.\nContinue?"),
                    Local.getString("Project is already exists"),
                    JOptionPane.YES_NO_OPTION);
            if (n != JOptionPane.YES_OPTION) {
                zip.close();
                return;
            }	
            ProjectManager.removeProject(pId);
        }
        Project prj = ProjectManager.createProject(pId, pTitle, new CalendarDate(pStartD), null);
        if (pEndD != null)
            prj.setEndDate(new CalendarDate(pEndD));
        //File prDir = new File(JN_DOCPATH + prj.getID());
        Enumeration files;           
        for (files = zip.entries(); files.hasMoreElements();){
            ZipEntry ze = (ZipEntry)files.nextElement();
            if ( ze.isDirectory() )
            {
               File theDirectory = new File (JN_DOCPATH + prj.getID()+ "/" + ze.getName() );
               // create this directory (including any necessary parent directories)
               theDirectory.mkdirs();
               theDirectory = null;
            }
            if ((!ze.getName().equals("__PROJECT_INFO__")) && (!ze.isDirectory())) {
                FileOutputStream out = new FileOutputStream(JN_DOCPATH + prj.getID() +"/"+ ze.getName());
                InputStream inp = zip.getInputStream(ze);
                
                byte[] buffer = new byte[1024];
                int len;

                while((len = inp.read(buffer)) >= 0)
                  out.write(buffer, 0, len);

                inp.close();
                out.close();
                
            }
        }
        zip.close();
        CurrentStorage.get().storeProjectManager();             
    }
    catch (Exception ex) {
        new ExceptionDialog(ex, "Failed to read from "+zipfile, "Make sure that this file is a Memoranda project archive.");
    }
}
 
开发者ID:ser316asu,项目名称:Wilmersdorf_SER316,代码行数:60,代码来源:ProjectPackager.java

示例14: isMultiDexApk

import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static boolean isMultiDexApk(File apkFile) throws ZipException, IOException {
	ZipFile f = new ZipFile(apkFile);
	boolean hasClasses2Dex = f.getEntry("classes2.dex") != null;
	f.close();
	return hasClasses2Dex;		
}
 
开发者ID:reddr,项目名称:LibScout,代码行数:7,代码来源:ApkUtils.java

示例15: toObsidianFile

import java.util.zip.ZipFile; //导入方法依赖的package包/类
@Override
public ObsidianFile toObsidianFile(File file)
{
	String error = "Failed to import from Qubble file: " + file.getName();

	try
	{
		String entityName = file.getName().split("\\.")[0];

		//Model
		QubbleModel qubbleModel = load(file);
		String duplicatePartName;
		if((duplicatePartName = containsDuplicateParts(qubbleModel)) != null) {
			error += ". The model contains the duplicate part " + duplicatePartName;
			throw new RuntimeException(error);
		}

		ObjModel objModel = qblConverter.qbl2obj(qubbleModel, 0.0625F);

		//Texture
		ZipFile zipFile = new ZipFile(file);
		ZipEntry textureEntry = zipFile.getEntry("base.png");

		byte[] textureBytes;

		if (textureEntry != null)
		{
			textureBytes = IOUtils.toByteArray(zipFile.getInputStream(textureEntry));
		}
		else
		{
			textureBytes = IOUtils.toByteArray(new FileInputStream(defaultTexture));
		}

		zipFile.close();

		byte[] modelBytes = createModelBytes(objModel.toStringList());
		return new ObsidianFile(entityName, modelBytes, textureBytes);
	}
	catch (Exception e1)
	{
		final JOptionPane pane = new JOptionPane(error);
		final JDialog d = pane.createDialog(null, "Import Error");
		d.setAlwaysOnTop(true);
		d.setVisible(true);
		e1.printStackTrace();
		return null;
	}
}
 
开发者ID:ObsidianSuite,项目名称:ObsidianSuite,代码行数:50,代码来源:ImporterQubble.java


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