本文整理汇总了Java中java.util.zip.ZipEntry.getMethod方法的典型用法代码示例。如果您正苦于以下问题:Java ZipEntry.getMethod方法的具体用法?Java ZipEntry.getMethod怎么用?Java ZipEntry.getMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.getMethod方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void writeEntry(ZipFile zf, ZipOutputStream os, ZipEntry ze)
throws IOException {
ZipEntry ze2 = new ZipEntry(ze.getName());
ze2.setMethod(ze.getMethod());
ze2.setTime(ze.getTime());
ze2.setComment(ze.getComment());
ze2.setExtra(ze.getExtra());
if (ze.getMethod() == ZipEntry.STORED) {
ze2.setSize(ze.getSize());
ze2.setCrc(ze.getCrc());
}
os.putNextEntry(ze2);
writeBytes(zf, ze, os);
}
示例2: unzipApk
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static List<String> unzipApk(String fileName, String filePath)
throws IOException {
FileUtils.checkDirectory(filePath);
List<String> storedFiles = new ArrayList<>();
ZipFile zipFile = new ZipFile(fileName);
Enumeration em = zipFile.entries();
while (em.hasMoreElements()) {
ZipEntry entry = (ZipEntry) em.nextElement();
if (entry.isDirectory()) {
new File(filePath, entry.getName()).mkdirs();
} else {
File file = new File(filePath + File.separator + entry.getName());
File parent = file.getParentFile();
if ((parent != null) && (!parent.exists())) {
parent.mkdirs();
}
if (entry.getMethod() == 0) {
storedFiles.add(entry.getName());
}
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos, 8192);
byte[] buf = new byte[BUFFER];
int len;
while ((len = bis.read(buf, 0, 8192)) != -1) {
fos.write(buf, 0, len);
}
bos.flush();
bos.close();
bis.close();
}
}
zipFile.close();
return storedFiles;
}
示例3: writeEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private long writeEntry(InputStream zis, ZipOutputStream output, ZipEntry newEntry) throws IOException {
// FIXME: is there a better way to do this, so that the whole input
// stream isn't in memory at once?
final byte[] contents = IOUtils.toByteArray(zis);
final CRC32 checksum = new CRC32();
checksum.update(contents);
if (newEntry.getMethod() == ZipEntry.STORED) {
newEntry.setSize(contents.length);
newEntry.setCrc(checksum.getValue());
}
output.putNextEntry(newEntry);
output.write(contents, 0, contents.length);
return checksum.getValue();
}
示例4: getCompressionLevel
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Override
public int getCompressionLevel(String fileName)
throws DirectoryException {
ZipEntry entry = mZipFile.getEntry(fileName);
if (entry == null) {
throw new PathNotExist("Entry not found: " + fileName);
}
return entry.getMethod();
}
示例5: writeZip
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Copies the content of a Jar/Zip archive into the receiver archive.
* <p/>An optional {@link IZipEntryFilter} allows to selectively choose which files
* to copy over.
*
* @param input the {@link InputStream} for the Jar/Zip to copy.
* @param filter the filter or <code>null</code>
* @throws IOException
*/
public void writeZip(InputStream input, IZipEntryFilter filter)
throws IOException, IZipEntryFilter.ZipAbortException {
ZipInputStream zis = new ZipInputStream(input);
try {
// loop on the entries of the intermediary package and put them in the final package.
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
// do not take directories or anything inside a potential META-INF folder.
if (entry.isDirectory() || name.startsWith("META-INF/")) {
continue;
}
// if we have a filter, we check the entry against it
if (filter != null && filter.checkEntry(name) == false) {
continue;
}
JarEntry newEntry;
// Preserve the STORED method of the input entry.
if (entry.getMethod() == JarEntry.STORED) {
newEntry = new JarEntry(entry);
} else {
// Create a new entry so that the compressed len is recomputed.
newEntry = new JarEntry(name);
}
writeEntry(zis, newEntry);
zis.closeEntry();
}
} finally {
zis.close();
}
}
示例6: zeString
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
static String zeString(ZipEntry ze) {
int store = (ze.getCompressedSize() > 0) ?
(int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 )
: 0 ;
// Follow unzip -lv output
return ze.getSize() + "\t" + ze.getMethod()
+ "\t" + ze.getCompressedSize() + "\t"
+ store + "%\t"
+ new Date(ze.getTime()) + "\t"
+ Long.toHexString(ze.getCrc()) + "\t"
+ ze.getName() ;
}