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


Java ZipArchiveEntry.getName方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipArchiveEntry.getName方法的具體用法?Java ZipArchiveEntry.getName怎麽用?Java ZipArchiveEntry.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.zip.ZipArchiveEntry的用法示例。


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

示例1: extractZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private void extractZip(ZipFile zipFile) {
  Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {

    ZipArchiveEntry entry = entries.nextElement();
    String fileName = entry.getName();
    File outputFile = new File(config.getExtractionFolder(), fileName);

    if (entry.isDirectory()) {
      makeDirectory(outputFile);
    } else {
      createNewFile(outputFile);
      try {
        InputStream inputStream = zipFile.getInputStream(entry);
        extractFile(inputStream, outputFile, fileName);
      } catch (IOException e) {
        throw new ExtractionException("Error extracting file '" + fileName + "' "
            + "from downloaded file: " + config.getDownloadTarget(), e);
      }
    }
  }
}
 
開發者ID:AlejandroRivera,項目名稱:embedded-rabbitmq,代碼行數:23,代碼來源:BasicExtractor.java

示例2: makeOnlyUnZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
public static void makeOnlyUnZip() throws ArchiveException, IOException{
		final InputStream is = new FileInputStream("D:/中文名字.zip");
		ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
		ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry();
		
		String dir = "D:/cnname";
		File filedir = new File(dir);
		if(!filedir.exists()){
			filedir.mkdir();
		}
//		OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
		OutputStream out = new FileOutputStream(new File(filedir, entry.getName()));
		IOUtils.copy(in, out);
		out.close();
		in.close();
	}
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:17,代碼來源:CompressExample.java

示例3: getStroomZipNameSet

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
public StroomZipNameSet getStroomZipNameSet() throws IOException {
	if (stroomZipNameSet == null) {
		stroomZipNameSet = new StroomZipNameSet(false);
		Enumeration<ZipArchiveEntry> entryE = getZipFile().getEntries();

		while (entryE.hasMoreElements()) {
			ZipArchiveEntry entry = entryE.nextElement();

			// Skip Dir's
			if (!entry.isDirectory()) {
				String fileName = entry.getName();
				stroomZipNameSet.add(fileName);
			}

			long entrySize = entry.getSize();
			if (entrySize == -1 || totalSize == -1) {
				// Can nolonger sum
			} else {
				totalSize += entrySize;
			}

		}

	}
	return stroomZipNameSet;
}
 
開發者ID:gchq,項目名稱:stroom-agent,代碼行數:27,代碼來源:StroomZipFile.java

示例4: getStroomZipNameSet

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
public StroomZipNameSet getStroomZipNameSet() throws IOException {
    if (stroomZipNameSet == null) {
        stroomZipNameSet = new StroomZipNameSet(false);
        Enumeration<ZipArchiveEntry> entryE = getZipFile().getEntries();

        while (entryE.hasMoreElements()) {
            ZipArchiveEntry entry = entryE.nextElement();

            // Skip Dir's
            if (!entry.isDirectory()) {
                String fileName = entry.getName();
                stroomZipNameSet.add(fileName);
            }

            long entrySize = entry.getSize();
            if (entrySize > 0) {
                totalSize += entrySize;
            }

        }
    }
    return stroomZipNameSet;
}
 
開發者ID:gchq,項目名稱:stroom-proxy,代碼行數:24,代碼來源:StroomZipFile.java

示例5: extract

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private static void extract(ZipArchiveEntry zipArchiveEntry, ZipFile zipFile, File outputDir) throws IOException {
    File extractedFile = new File(outputDir, zipArchiveEntry.getName());
    FileUtils.forceMkdir(extractedFile.getParentFile());
    if (zipArchiveEntry.isUnixSymlink()) {
        if (PosixUtil.isPosixFileStore(outputDir)) {
            logger.debug("Extracting [l] "+zipArchiveEntry.getName());
            String symlinkTarget = zipFile.getUnixSymlink(zipArchiveEntry);
            Files.createSymbolicLink(extractedFile.toPath(), new File(symlinkTarget).toPath());
        } else {
            logger.debug("Skipping ! [l] "+zipArchiveEntry.getName());
        }
    } else if (zipArchiveEntry.isDirectory()) {
        logger.debug("Extracting [d] "+zipArchiveEntry.getName());
        FileUtils.forceMkdir(extractedFile);
    } else {
        logger.debug("Extracting [f] "+zipArchiveEntry.getName());
        try (
                InputStream in = zipFile.getInputStream(zipArchiveEntry);
                OutputStream out = new FileOutputStream(extractedFile)
        ) {
            IOUtils.copy(in, out);
        }
    }
    updatePermissions(extractedFile, zipArchiveEntry.getUnixMode());
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:26,代碼來源:ZipUtil.java

示例6: extractZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private static void extractZipFile(final File destination, final ZipFile zipFile) throws IOException {
    final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();

    while (entries.hasMoreElements()) {
        final ZipArchiveEntry entry = entries.nextElement();
        final File entryDestination = new File(destination, entry.getName());

        if (entry.isDirectory()) {
            entryDestination.mkdirs();
        } else {
            entryDestination.getParentFile().mkdirs();
            final InputStream in = zipFile.getInputStream(entry);
            try (final OutputStream out = new FileOutputStream(entryDestination)) {
                IOUtils.copy(in, out);
                IOUtils.closeQuietly(in);
            }
        }
    }
}
 
開發者ID:awslabs,項目名稱:aws-codepipeline-plugin-for-jenkins,代碼行數:20,代碼來源:ExtractionTools.java

示例7: detectKmz

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private static MediaType detectKmz(ZipFile zip) {
    boolean kmlFound = false;

    Enumeration<ZipArchiveEntry> entries = zip.getEntries();
    while (entries.hasMoreElements()) {
        ZipArchiveEntry entry = entries.nextElement();
        String name = entry.getName();
        if (!entry.isDirectory()
                && name.indexOf('/') == -1 && name.indexOf('\\') == -1) {
            if (name.endsWith(".kml") && !kmlFound) {
                kmlFound = true;
            } else {
                return null;
            }
        }
    }

    if (kmlFound) {
        return MediaType.application("vnd.google-earth.kmz");
    } else {
        return null;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:24,代碼來源:ZipContainerDetector.java

示例8: detectIpa

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static MediaType detectIpa(ZipFile zip) {
    // Note - consider generalising this logic, if another format needs many regexp matching
    Set<Pattern> tmpPatterns = (Set<Pattern>)ipaEntryPatterns.clone();
    
    Enumeration<ZipArchiveEntry> entries = zip.getEntries();
    while (entries.hasMoreElements()) {
        ZipArchiveEntry entry = entries.nextElement();
        String name = entry.getName();
        
        Iterator<Pattern> ip = tmpPatterns.iterator();
        while (ip.hasNext()) {
            if (ip.next().matcher(name).matches()) {
                ip.remove();
            }
        }
        if (tmpPatterns.isEmpty()) {
            // We've found everything we need to find
            return MediaType.application("x-itunes-ipa");
        }
    }
    
    // If we get here, not all required entries were found
    return null;
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:26,代碼來源:ZipContainerDetector.java

示例9: extractEntireZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void extractEntireZip(@NotNull final File zip, @NotNull final File restoreDir) throws IOException {
    try (ZipFile zipFile = new ZipFile(zip)) {
        final Enumeration<ZipArchiveEntry> zipEntries = zipFile.getEntries();
        while (zipEntries.hasMoreElements()) {
            final ZipArchiveEntry zipEntry = zipEntries.nextElement();
            final File entryFile = new File(restoreDir, zipEntry.getName());
            if (zipEntry.isDirectory()) {
                entryFile.mkdirs();
            } else {
                entryFile.getParentFile().mkdirs();
                try (FileOutputStream target = new FileOutputStream(entryFile)) {
                    try (InputStream in = zipFile.getInputStream(zipEntry)) {
                        IOUtil.copyStreams(in, target, IOUtil.BUFFER_ALLOCATOR);
                    }
                }
            }
        }
    }
}
 
開發者ID:JetBrains,項目名稱:xodus,代碼行數:21,代碼來源:BackupTests.java

示例10: extractZipEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
 * Private Helper Method to Perform Extract of Compressed File with the Zip.
 *
 * @param zipFile
 * @param entry
 * @param outputDirectory
 * @throws java.io.IOException
 */
private static void extractZipEntry(ZipFile zipFile, ZipArchiveEntry entry, File outputDirectory)
        throws IOException {

    BufferedInputStream content = new BufferedInputStream(zipFile.getInputStream(entry), 16384);
    FileOutputStream fileOutputStream = new FileOutputStream(new File(outputDirectory + File.separator + entry.getName()));
    try {
        final byte[] buffer = new byte[16384];
        int n = 0;
        while (-1 != (n = content.read(buffer))) {
            fileOutputStream.write(buffer, 0, n);
        }

    } finally {
        content.close();
        fileOutputStream.flush();
        fileOutputStream.close();
    }
}
 
開發者ID:jaschenk,項目名稱:jeffaschenk-commons,代碼行數:27,代碼來源:ArchiveUtility.java

示例11: unzip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private void unzip(File file, String dest) throws IOException {
	try (ZipFile zip = new ZipFile(file)) {
		Enumeration<? extends ZipArchiveEntry> entries = zip.getEntries();
		while (entries.hasMoreElements()) {
			ZipArchiveEntry entry = entries.nextElement();
			File entryDestination = new File(dest, entry.getName());
			if (entry.isDirectory()) {
				entryDestination.mkdirs();
			} else {
				if (!entryDestination.getParentFile().exists()) {
					entryDestination.getParentFile().mkdirs();
				}
				try (InputStream in = zip.getInputStream(entry);
					OutputStream out = new FileOutputStream(entryDestination)) {
					IOUtils.copy(in, out);
				}
			}
		}
	}
}
 
開發者ID:openmrs,項目名稱:openmrs-module-owa,代碼行數:21,代碼來源:DefaultAppManager.java

示例12: getConfiguration

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
public Configuration getConfiguration(InputStreamDataSource configStream) throws IOException {
    Configuration configuration = new Configuration(false);
    try (ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(configStream.getInputStream())) {
        ZipArchiveEntry zipEntry = zipInputStream.getNextZipEntry();
        while (zipEntry != null) {
            String name = zipEntry.getName();
            if ( name.endsWith("core-site.xml") || name.endsWith("hdfs-site.xml") ) {
                if ( verbose ) System.err.println("Reading \"" + name + "\" into Configuration.");
                ByteArrayOutputStream boas = new ByteArrayOutputStream();
                IOUtils.copy(zipInputStream, boas);
                configuration.addResource(new ByteArrayInputStream(boas.toByteArray()), name);
            }
            zipEntry = zipInputStream.getNextZipEntry();
        }
    }
    return configuration;
}
 
開發者ID:ezbake,項目名稱:ezbakehelpers-cdh-config-exporter,代碼行數:18,代碼來源:Cdh2EzProperties.java

示例13: unpackZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
 * Unpacks a ZIP file to the destination directory.
 *
 * @throws MojoExecutionException
 *           if something goes wrong during unpacking the files.
 */
public void unpackZipFile(final File file, final File destinationDirectory,
    final String... exclusions) {

  Set<String> exclusionSet = new HashSet<>(Arrays.asList(exclusions));

  try (ZipFile zipFile = new ZipFile(file)) {
    Enumeration<? extends ZipArchiveEntry> entries = zipFile.getEntries();
    while (entries.hasMoreElements()) {
      ZipArchiveEntry entry = entries.nextElement();
      String name = entry.getName();

      if (!exclusionSet.contains(name)) {
        File destFile = new File(destinationDirectory, entry.getName());
        unpackEntry(destFile, zipFile, entry);
      }
    }
  } catch (IOException e) {
    throw new UncheckedIOException("Could not uncompress distribution package file "
        + file.getAbsolutePath() + " to target folder " + destinationDirectory.getAbsolutePath(),
        e);
  }
}
 
開發者ID:everit-org,項目名稱:eosgi-maven-plugin,代碼行數:29,代碼來源:FileManager.java

示例14: next

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
public InputStream next() {
    ZipArchiveEntry zipEntry = zipEntries.nextElement();

    StopWatch sw = new StopWatch(zipEntry.getName());

    InputStream feStream = null;

    try {
        return zipFile.getInputStream(zipEntry);
    } catch (IOException e) {
        IOUtils.closeQuietly(feStream);

        return null;
    } finally {
        IOUtils.closeQuietly(feStream);

        System.out.print(sw.prettyPrint());
    }
}
 
開發者ID:inbloom,項目名稱:secure-data-service,代碼行數:20,代碼來源:ZipFileIterator.java

示例15: unzip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
public static void unzip(File zipFile, File destination)
        throws IOException {
    ZipFile zip = new ZipFile(zipFile);
    try {
        Enumeration<ZipArchiveEntry> e = zip.getEntries();
        while (e.hasMoreElements()) {
            ZipArchiveEntry entry = e.nextElement();
            File file = new File(destination, entry.getName());
            if (entry.isDirectory()) {
                file.mkdirs();
            } else {
                InputStream is = zip.getInputStream(entry);
                File parent = file.getParentFile();
                if (parent != null && parent.exists() == false) {
                    parent.mkdirs();
                }
                FileOutputStream os = new FileOutputStream(file);
                try {
                    IOUtils.copy(is, os);
                } finally {
                    os.close();
                    is.close();
                }
                file.setLastModified(entry.getTime());
                int mode = entry.getUnixMode();
                if ((mode & EXEC_MASK) != 0) {
                    if (!file.setExecutable(true)) {
                    }
                }
            }
        }
    } finally {
        ZipFile.closeQuietly(zip);
    }
}
 
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:36,代碼來源:MavenDownloader.java


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