本文整理汇总了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);
}
}
}
}
示例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;
}
示例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());
}
示例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);
}
}
}
}
示例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));
}
}
示例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));
}
示例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;
}
}
示例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;
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
}
示例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();
}
}