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


Java ZipFile.getInputStream方法代碼示例

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


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

示例1: extractZip

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的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: getHashesFromZipFile

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public List<String> getHashesFromZipFile(File file) throws IOException {
  List<String> hashes = new ArrayList<>();
  ZipFile zipFile = new ZipFile(file);

  byte[] buf = new byte[65536];
  Enumeration<?> entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) entries.nextElement();
    int n;
    InputStream is = zipFile.getInputStream(zipArchiveEntry);
    ZipArchiveInputStream zis = new ZipArchiveInputStream(is);

    if (zis.canReadEntryData(zipArchiveEntry)) {
      while ((n = is.read(buf)) != -1) {
        if (n > 0) {
          hashes.add(DigestUtils.md5Hex(buf));
        }
      }
    }
    zis.close();
  }

  return hashes;
}
 
開發者ID:sysunite,項目名稱:excel-microservice,代碼行數:25,代碼來源:ExcelWriteControllerTest.java

示例3: extract

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的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

示例4: extractZipFile

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的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

示例5: runJarPatcher

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * Run jar patcher.
 *
 * @param originalName the original name
 * @param targetName the target name
 * @param originalZip the original zip
 * @param newZip the new zip
 * @param comparefiles the comparefiles
 * @throws Exception the exception
 */
private void runJarPatcher(String originalName, String targetName, ZipFile originalZip, ZipFile newZip, boolean comparefiles) throws Exception {
  try (ZipArchiveOutputStream output = new ZipArchiveOutputStream(new FileOutputStream(patchFile))) {
    new JarDelta().computeDelta(originalName, targetName, originalZip, newZip, output);
  }
  ZipFile patch = new ZipFile(patchFile);
  ZipArchiveEntry listEntry = patch.getEntry("META-INF/file.list");
  if (listEntry == null) {
    patch.close();
    throw new IOException("Invalid patch - list entry 'META-INF/file.list' not found");
  }
  BufferedReader patchlist = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
  String next = patchlist.readLine();
  String sourceName = next;
  next = patchlist.readLine();
  new JarPatcher(patchFile.getName(), sourceName).applyDelta(patch, new ZipFile(originalName), new ZipArchiveOutputStream(new FileOutputStream(resultFile)), patchlist);
  if (comparefiles) {
    compareFiles(new ZipFile(targetName), new ZipFile(resultFile));
  }
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:30,代碼來源:JarDeltaJarPatcherTest.java

示例6: testJarPatcherIdentFile

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * Tests JarDelta and JarPatcher on two identical files.
 *
 * @throws Exception the exception
 */
@Test
public void testJarPatcherIdentFile() throws Exception {
  ZipFile originalZip = makeSourceZipFile(sourceFile);
  new JarDelta().computeDelta(sourceFile.getAbsolutePath(), sourceFile.getAbsolutePath(), originalZip, originalZip, new ZipArchiveOutputStream(new FileOutputStream(patchFile)));
  ZipFile patch = new ZipFile(patchFile);
  ZipArchiveEntry listEntry = patch.getEntry("META-INF/file.list");
  if (listEntry == null) {
    patch.close();
    throw new IOException("Invalid patch - list entry 'META-INF/file.list' not found");
  }
  BufferedReader patchlist = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
  String next = patchlist.readLine();
  String sourceName = next;
  next = patchlist.readLine();
  ZipFile source = new ZipFile(sourceFile);
  new JarPatcher(patchFile.getName(), sourceName).applyDelta(patch, source, new ZipArchiveOutputStream(new FileOutputStream(resultFile)), patchlist);
  compareFiles(new ZipFile(sourceFile), new ZipFile(resultFile));
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:24,代碼來源:JarDeltaJarPatcherTest.java

示例7: detectType

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public static IWORKDocumentType detectType(ZipArchiveEntry entry,
    ZipFile zip) {
  try {
    if (entry == null) {
      return null;
    }

    InputStream stream = zip.getInputStream(entry);
    try {
      return detectType(stream);
    } finally {
      stream.close();
    }
  } catch (IOException e) {
    return null;
  }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:18,代碼來源:IWorkPackageParser.java

示例8: detectOpenDocument

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * OpenDocument files, along with EPub files, have a mimetype
 *  entry in the root of their Zip file. This entry contains the
 *  mimetype of the overall file, stored as a single string.  
 */
private static MediaType detectOpenDocument(ZipFile zip) {
    try {
        ZipArchiveEntry mimetype = zip.getEntry("mimetype");
        if (mimetype != null) {
            InputStream stream = zip.getInputStream(mimetype);
            try {
                return MediaType.parse(IOUtils.toString(stream, "UTF-8"));
            } finally {
                stream.close();
            }
        } else {
            return null;
        }
    } catch (IOException e) {
        return null;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:23,代碼來源:ZipContainerDetector.java

示例9: extractZipEntry

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的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

示例10: unpackEntry

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private void unpackEntry(final File destFile, final ZipFile zipFile, final ZipArchiveEntry entry)
    throws IOException, ZipException {
  if (entry.isDirectory()) {
    touchedFiles.add(destFile);
    destFile.mkdirs();
  } else if (!isSameFile(destFile, entry.getSize(),
      entry.getLastModifiedDate().getTime())) {
    File parentFolder = destFile.getParentFile();
    parentFolder.mkdirs();
    InputStream inputStream = zipFile.getInputStream(entry);
    overCopyFile(Channels.newChannel(inputStream), entry.getSize(),
        entry.getLastModifiedDate().getTime(), destFile);
    FileManager.setPermissionsOnFile(destFile, entry);
  } else {
    touchedFiles.add(destFile);
  }
}
 
開發者ID:everit-org,項目名稱:eosgi-maven-plugin,代碼行數:18,代碼來源:FileManager.java

示例11: readFirstZipEntry

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
 * Reads the first file entry in a zip file and returns it's contents
 * as uncompressed byte-array
 * @param zipFile the zip file to read from
 * @return the first file entry (uncompressed)
 * @throws IOException if there is an error accessing the zip file
 */
public static byte[] readFirstZipEntry(File zipFile) throws IOException {
    // open zip
    ZipFile zf = new ZipFile(zipFile);
    Enumeration<ZipArchiveEntry> entries = zf.getEntries();

    // read first entry to byte[]
    ZipArchiveEntry entry = entries.nextElement();
    InputStream is = zf.getInputStream(entry);
    byte[] raw = ByteStreams.toByteArray(is);

    // close all streams and return byte[]
    is.close();
    zf.close();
    return raw;
}
 
開發者ID:klamann,項目名稱:maps4cim,代碼行數:23,代碼來源:Compression.java

示例12: unzip

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的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

示例13: checkAndReadManifest

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private void checkAndReadManifest(String entryName, ZipArchiveEntry zae, ZipFile zipFile) throws IOException {
    InputStream inStream = zipFile.getInputStream(zae);
    try {
        JSONManifest manifest =
                BarFileUtils.readJsonEntry(inStream, entryName, JSONManifest.class);
        if (!manifest.checkSchema()) {
            throw PersoniumCoreException.BarInstall.BAR_FILE_INVALID_STRUCTURES.params(entryName);
        }
        this.manifestJson = manifest.getJson();
    } finally {
        IOUtils.closeQuietly(inStream);
    }
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:14,代碼來源:BarFileInstaller.java

示例14: extractRdlBinary

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
void extractRdlBinary(final String rdlBinSuffix) throws IOException {
    if (rdlBinSuffix.equals("darwin")) {
        File file = fileUtils.getFileFromResource("/rdl-bin/rdl.zip");
        ZipFile zipFile = new ZipFile(file);
        InputStream inputStream = zipFile.getInputStream(zipFile.getEntry(PathUtils.RDL_BINARY));
        fileUtils.writeResourceAsExecutable(inputStream, pathUtils.getRdlBinaryPath());
    } else {
        // the tgz file for linux
        fileUtils.unTarZip("/rdl-bin/rdl.tgz", pathUtils.getBinPath(), true);
        InputStream rdlStream = new FileInputStream(pathUtils.getRdlBinaryPath());
        if (rdlStream != null) {
            fileUtils.writeResourceAsExecutable(rdlStream, pathUtils.getRdlBinaryPath());
        }
    }
}
 
開發者ID:yahoo,項目名稱:parsec,代碼行數:16,代碼來源:ParsecInitTask.java

示例15: decompressZip

import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public void decompressZip(File zipFile, String dir) throws IOException {
	ZipFile zf = new ZipFile(zipFile);
	try {
		for (Enumeration<ZipArchiveEntry> entries = zf.getEntries(); entries
				.hasMoreElements();) {
			ZipArchiveEntry ze = entries.nextElement();
			// 不存在則創建目標文件夾。
			File targetFile = new File(dir, ze.getName());
			// 遇到根目錄時跳過。
			if (ze.getName().lastIndexOf("/") == (ze.getName().length() - 1)) {
				continue;
			}
			// 如果文件夾不存在,創建文件夾。
			if (!targetFile.getParentFile().exists()) {
				targetFile.getParentFile().mkdirs();
			}

			InputStream i = zf.getInputStream(ze);
			OutputStream o = null;
			try {
				o = new FileOutputStream(targetFile);
				IOUtils.copy(i, o);
			} finally {
				if (i != null) {
					i.close();
				}
				if (o != null) {
					o.close();
				}
			}
		}
	} finally {
		zf.close();
	}
}
 
開發者ID:hoozheng,項目名稱:AndroidRobot,代碼行數:36,代碼來源:ZipUtil.java


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