本文整理汇总了Java中java.util.zip.ZipFile.close方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.close方法的具体用法?Java ZipFile.close怎么用?Java ZipFile.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例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);
}
}
示例3: PackageContents
import java.util.zip.ZipFile; //导入方法依赖的package包/类
public PackageContents(File targetFile, PackageType pkg) throws IOException {
this.pkg = pkg;
file = targetFile;
packageFile = new ZipFile(targetFile);
subfiles = new TreeMap<>();
files = DataUtil.enumerationAsStream(packageFile.entries())
.map(entry -> new ZipFullEntry(packageFile, entry))
.peek(this::observeFileEntry)
.collect(Collectors.toMap(
ZipFullEntry::getName,
e -> new FileContents(e, this),
(k, v) -> k,
TreeMap::new));
files.putAll(subfiles);
packageFile.close();
if (pkg instanceof CrxPackage) {
((CrxPackage) pkg).setContents(this);
}
}
示例4: getDataFromZippedRoot
import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
* Searches for entries in provided zipped resource. Returns a collection of pairs. The first element in each pair
* is a {@link ZipEntry} that points to the test data file while the second element in each pair is a blacklist of
* tests that are expected to fail.
*
* @param rootName
* the fq-name of zip archive
* @param configProvider
* factory for configurations
* @return the test data.
* @throws URISyntaxException
* cannot happen
* @throws IOException
* if something wents wrong while reading the archive or blacklist files
*/
public static Collection<JSLibSingleTestConfig> getDataFromZippedRoot(String rootName,
JSLibSingleTestConfigProvider configProvider)
throws IOException, URISyntaxException {
URL rootURL = Thread.currentThread().getContextClassLoader().getResource(rootName);
ZipFile root = new ZipFile(new File(rootURL.toURI()));
Collection<JSLibSingleTestConfig> entries = new ArrayList<>();
try {
filterDataFilesFromZippedFolder(root, rootName, entries, configProvider);
} finally {
root.close();
}
return entries;
}
示例5: scan
import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
* Reads class entries from the jar file into ClassFile instances.
* Returns the number of classes scanned.
*/
public int scan() throws IOException {
int n = 0;
ZipFile zf = new ZipFile(jarName);
Enumeration files = zf.entries();
while (files.hasMoreElements()) {
ZipEntry entry = (ZipEntry)files.nextElement();
String name = entry.getName();
if (name.endsWith(".class")) {
InputStream in = zf.getInputStream(entry);
ClassFile cf = new ClassFile(in, includeCode);
if (toString)
try {
cf.toString(); // forces loading of attributes.
} catch (InvalidClassFileAttributeException ex) {
System.out.println("error accessing " + name);
throw ex;
}
in.close();
n++;
}
}
zf.close();
return n;
}
示例6: ExtractZipEntry
import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static byte[] ExtractZipEntry(File input, String entryName) {
try {
ZipFile zip = new ZipFile(input);
try {
ZipEntry entry = zip.getEntry(entryName);
if (entry == null) {
return null;
}
InputStream stream = zip.getInputStream(entry);
try {
byte[] buffer = new byte[(int) entry.getSize()];
stream.read(buffer);
return buffer;
} finally {
stream.close();
}
} finally {
zip.close();
}
} catch (IOException e)
{
return null;
}
}
示例7: getCertificateFromZip
import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static Certificate getCertificateFromZip(String zipPath, String certPath) throws Exception {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
ZipFile zip = new ZipFile(new File(zipPath));
InputStream in = zip.getInputStream(zip.getEntry(certPath));
Certificate certificate = certificateFactory.generateCertificates(in).iterator().next();
in.close();
zip.close();
return certificate;
}
示例8: 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;
}
示例9: listJarPackages
import java.util.zip.ZipFile; //导入方法依赖的package包/类
public void listJarPackages(File jarFile, JarFilePackageListener listener) {
if (jarFile == null) {
throw new IllegalArgumentException("jarFile is null!");
}
final String jarFileAbsolutePath = jarFile.getAbsolutePath();
if (!jarFile.exists()) {
throw new IllegalArgumentException("jarFile doesn't exists! (" + jarFileAbsolutePath + ")");
}
if (!jarFile.isFile()) {
throw new IllegalArgumentException("jarFile is not a file! (" + jarFileAbsolutePath + ")");
}
if (!hasExtension(jarFile, ".jar")) {
throw new IllegalArgumentException("jarFile is not a jarFile! (" + jarFileAbsolutePath + ")");
}
try {
ZipFile zipFile = new ZipFile(jarFile);
try {
final Enumeration<? extends ZipEntry> zipFileEntries = zipFile.entries();
while (zipFileEntries.hasMoreElements()) {
final ZipEntry zipFileEntry = zipFileEntries.nextElement();
if (zipFileEntry.isDirectory()) {
final String zipFileEntryName = zipFileEntry.getName();
if (!zipFileEntryName.startsWith("META-INF")) {
listener.receivePackage(zipFileEntryName);
}
}
}
} finally {
zipFile.close();
}
} catch (IOException e) {
throw new GradleException("failed to scan jar file for packages (" + jarFileAbsolutePath + ")", e);
}
}
示例10: unZip
import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
* Given a File input it will unzip the file in a the unzip directory
* passed as the second parameter
* @param inFile The zip file as input
* @param unzipDir The unzip directory where to unzip the zip file.
* @throws IOException
*/
public static void unZip(File inFile, File unzipDir) throws IOException {
Enumeration<? extends ZipEntry> entries;
ZipFile zipFile = new ZipFile(inFile);
try {
entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
InputStream in = zipFile.getInputStream(entry);
try {
File file = new File(unzipDir, entry.getName());
if (!file.getParentFile().mkdirs()) {
if (!file.getParentFile().isDirectory()) {
throw new IOException("Mkdirs failed to create " +
file.getParentFile().toString());
}
}
OutputStream out = new FileOutputStream(file);
try {
byte[] buffer = new byte[8192];
int i;
while ((i = in.read(buffer)) != -1) {
out.write(buffer, 0, i);
}
} finally {
out.close();
}
} finally {
in.close();
}
}
}
} finally {
zipFile.close();
}
}
示例11: isCorrectType
import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static boolean isCorrectType(MysterType type, File file) {
if (file.length() == 0)
return false; //all 0k files are bad.
TypeDescription typeDescription = TypeDescriptionList.getDefault().get(
type);
if (typeDescription == null)
return true; //no information on this type, allow everything.
String[] extensions = typeDescription.getExtensions(); //getExtensions
// is slow so we
// only want to
// exce it once.
if (extensions.length == 0)
return true;//no information on this type, allow everything.
if (hasExtension(file.getName(), extensions))//entry.extensions))
return true;
if (typeDescription.isArchived() && isArchive(file.getName())) {
try {
ZipFile zipFile = new ZipFile(file);
try {
for (Enumeration entries = zipFile.entries(); entries
.hasMoreElements();) {
ZipEntry zipEntry = (ZipEntry) entries.nextElement();
if (hasExtension(zipEntry.getName(), extensions))
return true;
}
} finally {
zipFile.close();
}
} catch (java.io.IOException e) {
return false;
}
}
return false;
}
示例12: quietClose
import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static void quietClose(ZipFile zip){
try {
if (zip != null) {
zip.close();
}
}catch(Throwable e){
}
}
示例13: 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 (StrUtils.startsWith(s1, p_collectFilesZIP_1_) && StrUtils.endsWith(s1, 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];
}
}
示例14: isODFDocument
import java.util.zip.ZipFile; //导入方法依赖的package包/类
/** Indica si un fichero tiene la estructura de un documento ODF.
* @param document
* Fichero a analizar
* @return Devuelve <code>true</code> si el fichero era un ODF, <code>false</code> en caso contrario.
* @throws IOException Si ocurren problemas leyendo el fichero */
public static boolean isODFDocument(final byte[] document) throws IOException {
final ZipFile zipFile = AOFileUtils.createTempZipFile(document);
final boolean ret = isODFFile(zipFile);
zipFile.close();
return ret;
}
示例15: 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);
}