本文整理了Java中java.util.zip.ZipEntry.setMethod()
方法的一些代码示例,展示了ZipEntry.setMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry.setMethod()
方法的具体详情如下:
包路径:java.util.zip.ZipEntry
类名称:ZipEntry
方法名:setMethod
[英]Sets the compression method for this entry to either DEFLATED or STORED. The default is DEFLATED, which will cause the size, compressed size, and CRC to be set automatically, and the entry's data to be compressed. If you switch to STOREDnote that you'll have to set the size (or compressed size; they must be the same, but it's okay to only set one) and CRC yourself because they must appear before the user data in the resulting zip file. See #setSize and #setCrc.
[中]将此条目的压缩方法设置为“已放气”或“已存储”。默认值为DEFLATED,这将导致自动设置大小、压缩大小和CRC,并压缩条目的数据。如果切换到STOREDnote,则必须自行设置大小(或压缩大小;它们必须相同,但可以只设置一个)和CRC,因为它们必须出现在生成的zip文件中的用户数据之前。请参阅#设置大小和#设置CRC。
代码示例来源:origin: Tencent/tinker
private static void zipFile(File resFile, ZipOutputStream zipout, String rootpath) throws IOException {
rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator) + resFile.getName();
if (resFile.isDirectory()) {
File[] fileList = resFile.listFiles();
for (File file : fileList) {
zipFile(file, zipout, rootpath);
}
} else {
final byte[] fileContents = readContents(resFile);
//linux format!!
if (rootpath.contains("\\")) {
rootpath = rootpath.replace("\\", "/");
}
ZipEntry entry = new ZipEntry(rootpath);
// if (compressMethod == ZipEntry.DEFLATED) {
entry.setMethod(ZipEntry.DEFLATED);
// } else {
// entry.setMethod(ZipEntry.STORED);
// entry.setSize(fileContents.length);
// final CRC32 checksumCalculator = new CRC32();
// checksumCalculator.update(fileContents);
// entry.setCrc(checksumCalculator.getValue());
// }
zipout.putNextEntry(entry);
zipout.write(fileContents);
zipout.flush();
zipout.closeEntry();
}
}
代码示例来源:origin: scouter-project/scouter
static public void sendZipFile(ZipOutputStream zos, File file) throws Exception {
String zipFilename = file.getAbsolutePath();
int index = zipFilename.lastIndexOf(File.separator);
if(index >= 0){
zipFilename = zipFilename.substring(index+1);
}
ZipEntry zipEntry = new ZipEntry(zipFilename);
zipEntry.setMethod(ZipEntry.DEFLATED);
zipEntry.setSize(file.length());
zos.putNextEntry(zipEntry);
int readSize = 0;
byte[] buffer = new byte[FILE_BUFFER_SIZE];
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
while (0 != (readSize = bis.read(buffer))) {
if(-1 == readSize) break;
zos.write(buffer, 0, readSize);
}
bis.close();
}
代码示例来源:origin: scouter-project/scouter
static public void sendZipFile(ZipOutputStream zos, File file) throws Exception {
String zipFilename = file.getAbsolutePath();
int index = zipFilename.lastIndexOf(File.separator);
if(index >= 0){
zipFilename = zipFilename.substring(index+1);
}
ZipEntry zipEntry = new ZipEntry(zipFilename);
zipEntry.setMethod(ZipEntry.DEFLATED);
zipEntry.setSize(file.length());
zos.putNextEntry(zipEntry);
int readSize = 0;
byte[] buffer = new byte[FILE_BUFFER_SIZE];
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
while (0 != (readSize = bis.read(buffer))) {
if(-1 == readSize) break;
zos.write(buffer, 0, readSize);
}
bis.close();
}
代码示例来源:origin: iBotPeaches/Apktool
private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files)
throws BrutException, IOException {
File unknownFileDir = new File(appDir, UNK_DIRNAME);
// loop through unknown files
for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) {
File inputFile = new File(unknownFileDir, BrutIO.sanitizeUnknownFile(unknownFileDir, unknownFileInfo.getKey()));
if (inputFile.isDirectory()) {
continue;
}
ZipEntry newEntry = new ZipEntry(unknownFileInfo.getKey());
int method = Integer.parseInt(unknownFileInfo.getValue());
LOGGER.fine(String.format("Copying unknown file %s with method %d", unknownFileInfo.getKey(), method));
if (method == ZipEntry.STORED) {
newEntry.setMethod(ZipEntry.STORED);
newEntry.setSize(inputFile.length());
newEntry.setCompressedSize(-1);
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile));
CRC32 crc = BrutIO.calculateCrc(unknownFile);
newEntry.setCrc(crc.getValue());
} else {
newEntry.setMethod(ZipEntry.DEFLATED);
}
outputFile.putNextEntry(newEntry);
BrutIO.copy(inputFile, outputFile);
outputFile.closeEntry();
}
}
代码示例来源:origin: scouter-project/scouter
static public void sendZipFile(ZipOutputStream zos, File file) throws Exception {
String zipFilename = file.getAbsolutePath();
int index = zipFilename.lastIndexOf(File.separator);
if(index >= 0){
zipFilename = zipFilename.substring(index+1);
}
ZipEntry zipEntry = new ZipEntry(zipFilename);
zipEntry.setMethod(ZipEntry.DEFLATED);
zipEntry.setSize(file.length());
zos.putNextEntry(zipEntry);
int readSize = 0;
byte[] buffer = new byte[FILE_BUFFER_SIZE];
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
while (0 != (readSize = bis.read(buffer))) {
if(-1 == readSize) break;
zos.write(buffer, 0, readSize);
}
bis.close();
}
代码示例来源:origin: scouter-project/scouter
static public void sendZipFile(ZipOutputStream zos, File file) throws Exception {
String zipFilename = file.getAbsolutePath();
int index = zipFilename.lastIndexOf(File.separator);
if(index >= 0){
zipFilename = zipFilename.substring(index+1);
}
ZipEntry zipEntry = new ZipEntry(zipFilename);
zipEntry.setMethod(ZipEntry.DEFLATED);
zipEntry.setSize(file.length());
zos.putNextEntry(zipEntry);
int readSize = 0;
byte[] buffer = new byte[FILE_BUFFER_SIZE];
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
while (0 != (readSize = bis.read(buffer))) {
if(-1 == readSize) break;
zos.write(buffer, 0, readSize);
}
bis.close();
}
代码示例来源:origin: iBotPeaches/Apktool
zipEntry.setMethod(ZipEntry.STORED);
zipEntry.setSize(file.length());
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(file));
unknownFile.close();
} else {
zipEntry.setMethod(ZipEntry.DEFLATED);
代码示例来源:origin: scouter-project/scouter
static public void sendZipFile(ZipOutputStream zos, File file) throws Exception {
String zipFilename = file.getAbsolutePath();
int index = zipFilename.lastIndexOf(File.separator);
if(index >= 0){
zipFilename = zipFilename.substring(index+1);
}
ZipEntry zipEntry = new ZipEntry(zipFilename);
zipEntry.setMethod(ZipEntry.DEFLATED);
zipEntry.setSize(file.length());
zos.putNextEntry(zipEntry);
int readSize = 0;
byte[] buffer = new byte[FILE_BUFFER_SIZE];
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
while (0 != (readSize = bis.read(buffer))) {
if(-1 == readSize) break;
zos.write(buffer, 0, readSize);
}
bis.close();
}
代码示例来源:origin: guoguibing/librec
entry.setMethod(ZipEntry.STORED);
entry.setCompressedSize(file.length());
entry.setSize(file.length());
代码示例来源:origin: pxb1988/dex2jar
ZipEntry nEntry = new ZipEntry(e.getName());
nEntry.setMethod(e.getMethod() == com.googlecode.d2j.util.zip.ZipEntry.STORED ? ZipEntry.STORED
: ZipEntry.DEFLATED);
zos.putNextEntry(nEntry);
代码示例来源:origin: Sable/soot
private void copyAllButClassesDexAndSigFiles(ZipFile source, ZipOutputStream destination) throws IOException {
Enumeration<? extends ZipEntry> sourceEntries = source.entries();
while (sourceEntries.hasMoreElements()) {
ZipEntry sourceEntry = sourceEntries.nextElement();
String sourceEntryName = sourceEntry.getName();
if (sourceEntryName.endsWith(".dex") || isSignatureFile(sourceEntryName)) {
continue;
}
// separate ZipEntry avoids compression problems due to encodings
ZipEntry destinationEntry = new ZipEntry(sourceEntryName);
// use the same compression method as the original (certain files
// are stored, not compressed)
destinationEntry.setMethod(sourceEntry.getMethod());
// copy other necessary fields for STORE method
destinationEntry.setSize(sourceEntry.getSize());
destinationEntry.setCrc(sourceEntry.getCrc());
// finally craft new entry
destination.putNextEntry(destinationEntry);
InputStream zipEntryInput = source.getInputStream(sourceEntry);
byte[] buffer = new byte[2048];
int bytesRead = zipEntryInput.read(buffer);
while (bytesRead > 0) {
destination.write(buffer, 0, bytesRead);
bytesRead = zipEntryInput.read(buffer);
}
zipEntryInput.close();
}
}
代码示例来源:origin: google/j2objc
outEntry.setMethod(entry.getMethod());
outEntry.setComment(entry.getComment());
outEntry.setSize(bytes.length);
代码示例来源:origin: zeroturnaround/zt-zip
public ZipEntry getEntry() {
ZipEntry entry = new ZipEntry(path);
if (bytes != null) {
entry.setSize(bytes.length);
}
if(compressionMethod != -1) {
entry.setMethod(compressionMethod);
}
if(crc != -1L) {
entry.setCrc(crc);
}
entry.setTime(time);
return entry;
}
代码示例来源:origin: org.easymock/easymock
outEntry.setMethod(entry.getMethod());
outEntry.setComment(entry.getComment());
outEntry.setSize(bytes.length);
代码示例来源:origin: cglib/cglib
outEntry.setMethod(entry.getMethod());
outEntry.setComment(entry.getComment());
outEntry.setSize(bytes.length);
代码示例来源:origin: cglib/cglib
outEntry.setMethod(entry.getMethod());
outEntry.setComment(entry.getComment());
outEntry.setSize(bytes.length);
代码示例来源:origin: org.apache.ant/ant
outputEntry.setTime(inputEntry.getTime());
if (compression) {
outputEntry.setMethod(ZipEntry.DEFLATED);
outputEntry.setMethod(ZipEntry.STORED);
outputEntry.setCrc(inputEntry.getCrc());
outputEntry.setSize(inputEntry.getSize());
代码示例来源:origin: zeroturnaround/zt-zip
/**
* Copy entry with another name.
*
* @param original - zipEntry to copy
* @param newName - new entry name, optional, if null, ogirinal's entry
* @return copy of the original entry, but with the given name
*/
static ZipEntry copy(ZipEntry original, String newName) {
ZipEntry copy = new ZipEntry(newName == null ? original.getName() : newName);
if (original.getCrc() != -1) {
copy.setCrc(original.getCrc());
}
if (original.getMethod() != -1) {
copy.setMethod(original.getMethod());
}
if (original.getSize() >= 0) {
copy.setSize(original.getSize());
}
if (original.getExtra() != null) {
copy.setExtra(original.getExtra());
}
copy.setComment(original.getComment());
copy.setTime(original.getTime());
return copy;
}
代码示例来源:origin: robovm/robovm
ze.setMethod(method);
代码示例来源:origin: robovm/robovm
currentEntry.time = ceLastModifiedTime;
currentEntry.modDate = ceLastModifiedDate;
currentEntry.setMethod(ceCompressionMethod);
if (ceSize != -1) {
currentEntry.setCrc(ceCrc);
内容来源于网络,如有侵权,请联系作者删除!