本文整理汇总了Java中java.util.zip.ZipEntry.setCompressedSize方法的典型用法代码示例。如果您正苦于以下问题:Java ZipEntry.setCompressedSize方法的具体用法?Java ZipEntry.setCompressedSize怎么用?Java ZipEntry.setCompressedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.setCompressedSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyExistingFiles
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void copyExistingFiles(ZipFile inputFile, ZipOutputStream outputFile) throws IOException {
// First, copy the contents from the existing outFile:
Enumeration<? extends ZipEntry> entries = inputFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = new ZipEntry(entries.nextElement());
// We can't reuse the compressed size because it depends on compression sizes.
entry.setCompressedSize(-1);
outputFile.putNextEntry(entry);
// No need to create directory entries in the final apk
if (! entry.isDirectory()) {
BrutIO.copy(inputFile, outputFile, entry);
}
outputFile.closeEntry();
}
}
示例2: copyUnknownFiles
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files)
throws 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, 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();
}
}
示例3: zipFolder
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Zip a given folder
*
* @param dirPath
* a given folder: must be all files (not sub-folders)
* @param filePath
* zipped file
* @throws Exception
*/
public static void zipFolder(String dirPath, String filePath) throws Exception {
File outFile = new File(filePath);
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outFile));
int bytesRead;
byte[] buffer = new byte[1024];
CRC32 crc = new CRC32();
for (File file : listFiles(dirPath)) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
crc.reset();
while ((bytesRead = bis.read(buffer)) != -1) {
crc.update(buffer, 0, bytesRead);
}
bis.close();
// Reset to beginning of input stream
bis = new BufferedInputStream(new FileInputStream(file));
ZipEntry entry = new ZipEntry(file.getName());
entry.setMethod(ZipEntry.STORED);
entry.setCompressedSize(file.length());
entry.setSize(file.length());
entry.setCrc(crc.getValue());
zos.putNextEntry(entry);
while ((bytesRead = bis.read(buffer)) != -1) {
zos.write(buffer, 0, bytesRead);
}
bis.close();
}
zos.close();
Logs.debug("A zip-file is created to: {}", outFile.getPath());
}
示例4: writeEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void writeEntry(JarOutputStream j, String name,
long mtime, long lsize, boolean deflateHint,
ByteBuffer data0, ByteBuffer data1) throws IOException {
int size = (int)lsize;
if (size != lsize)
throw new IOException("file too large: "+lsize);
CRC32 crc32 = _crc32;
if (_verbose > 1)
Utils.log.fine("Writing entry: "+name+" size="+size
+(deflateHint?" deflated":""));
if (_buf.length < size) {
int newSize = size;
while (newSize < _buf.length) {
newSize <<= 1;
if (newSize <= 0) {
newSize = size;
break;
}
}
_buf = new byte[newSize];
}
assert(_buf.length >= size);
int fillp = 0;
if (data0 != null) {
int size0 = data0.capacity();
data0.get(_buf, fillp, size0);
fillp += size0;
}
if (data1 != null) {
int size1 = data1.capacity();
data1.get(_buf, fillp, size1);
fillp += size1;
}
while (fillp < size) {
// Fill in rest of data from the stream itself.
int nr = in.read(_buf, fillp, size - fillp);
if (nr <= 0) throw new IOException("EOF at end of archive");
fillp += nr;
}
ZipEntry z = new ZipEntry(name);
z.setTime(mtime * 1000);
if (size == 0) {
z.setMethod(ZipOutputStream.STORED);
z.setSize(0);
z.setCrc(0);
z.setCompressedSize(0);
} else if (!deflateHint) {
z.setMethod(ZipOutputStream.STORED);
z.setSize(size);
z.setCompressedSize(size);
crc32.reset();
crc32.update(_buf, 0, size);
z.setCrc(crc32.getValue());
} else {
z.setMethod(Deflater.DEFLATED);
z.setSize(size);
}
j.putNextEntry(z);
if (size > 0)
j.write(_buf, 0, size);
j.closeEntry();
if (_verbose > 0) Utils.log.info("Writing " + Utils.zeString(z));
}
示例5: readEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
static ZipEntry readEntry(ByteBuffer in) throws IOException {
int sig = in.getInt();
if (sig != CENSIG) {
throw new ZipException("Central Directory Entry not found");
}
in.position(8);
int gpbf = in.getShort() & 0xffff;
if ((gpbf & GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}
int compressionMethod = in.getShort() & 0xffff;
int time = in.getShort() & 0xffff;
int modDate = in.getShort() & 0xffff;
// These are 32-bit values in the file, but 64-bit fields in this object.
long crc = ((long) in.getInt()) & 0xffffffffL;
long compressedSize = ((long) in.getInt()) & 0xffffffffL;
long size = ((long) in.getInt()) & 0xffffffffL;
int nameLength = in.getShort() & 0xffff;
int extraLength = in.getShort() & 0xffff;
int commentByteCount = in.getShort() & 0xffff;
// This is a 32-bit value in the file, but a 64-bit field in this object.
in.position(42);
long localHeaderRelOffset = ((long) in.getInt()) & 0xffffffffL;
byte[] nameBytes = new byte[nameLength];
in.get(nameBytes, 0, nameBytes.length);
String name = new String(nameBytes, 0, nameBytes.length, UTF_8);
ZipEntry entry = new ZipEntry(name);
entry.setMethod(compressionMethod);
entry.setTime(getTime(time, modDate));
entry.setCrc(crc);
entry.setCompressedSize(compressedSize);
entry.setSize(size);
// The RI has always assumed UTF-8. (If GPBF_UTF8_FLAG isn't set, the encoding is
// actually IBM-437.)
if (commentByteCount > 0) {
byte[] commentBytes = new byte[commentByteCount];
in.get(commentBytes, 0, commentByteCount);
entry.setComment(new String(commentBytes, 0, commentBytes.length, UTF_8));
}
if (extraLength > 0) {
byte[] extra = new byte[extraLength];
in.get(extra, 0, extraLength);
entry.setExtra(extra);
}
return entry;
}