本文整理了Java中java.util.zip.ZipEntry.setSize()
方法的一些代码示例,展示了ZipEntry.setSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry.setSize()
方法的具体详情如下:
包路径:java.util.zip.ZipEntry
类名称:ZipEntry
方法名:setSize
[英]Sets the uncompressed size of this ZipEntry.
[中]设置此ZipEntry的未压缩大小。
代码示例来源:origin: stackoverflow.com
public static byte[] zipBytes(String filename, byte[] input) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
ZipEntry entry = new ZipEntry(filename);
entry.setSize(input.length);
zos.putNextEntry(entry);
zos.write(input);
zos.closeEntry();
zos.close();
return baos.toByteArray();
}
代码示例来源:origin: apache/ignite
/**
* Zips bytes.
*
* @param input Input bytes.
* @return Zipped byte array.
* @throws IOException If failed.
*/
public static byte[] zipBytes(byte[] input) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(DFLT_BUFFER_SIZE);
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
ZipEntry entry = new ZipEntry("");
try {
entry.setSize(input.length);
zos.putNextEntry(entry);
zos.write(input);
}
finally {
zos.closeEntry();
}
}
return baos.toByteArray();
}
代码示例来源:origin: apache/ignite
/**
* Zips byte array.
*
* @param input Input bytes.
* @param initBufSize Initial buffer size.
* @return Zipped byte array.
* @throws IOException If failed.
*/
public static byte[] zipBytes(byte[] input, int initBufSize) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(initBufSize);
try (ZipOutputStream zos = new ZipOutputStream(bos)) {
try {
ZipEntry entry = new ZipEntry("");
entry.setSize(input.length);
zos.putNextEntry(entry);
zos.write(input);
}
finally {
zos.closeEntry();
}
}
return bos.toByteArray();
}
代码示例来源:origin: redisson/redisson
public static void addFolderToZip(ZipOutputStream zos, String path, String comment) throws IOException {
while (path.length() != 0 && path.charAt(0) == '/') {
path = path.substring(1);
}
// add folder record
if (!StringUtil.endsWithChar(path, '/')) {
path += '/';
}
ZipEntry zipEntry = new ZipEntry(path);
zipEntry.setTime(System.currentTimeMillis());
if (comment != null) {
zipEntry.setComment(comment);
}
zipEntry.setSize(0);
zipEntry.setCrc(0);
zos.putNextEntry(zipEntry);
zos.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: 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: 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: iBotPeaches/Apktool
if (mDoNotCompress != null && (mDoNotCompress.contains(extension) || mDoNotCompress.contains(zipEntry.getName()))) {
zipEntry.setMethod(ZipEntry.STORED);
zipEntry.setSize(file.length());
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(file));
CRC32 crc = BrutIO.calculateCrc(unknownFile);
代码示例来源:origin: oblac/jodd
public static void addFolderToZip(final ZipOutputStream zos, String path, final String comment) throws IOException {
while (path.length() != 0 && path.charAt(0) == '/') {
path = path.substring(1);
}
// add folder record
if (!StringUtil.endsWithChar(path, '/')) {
path += '/';
}
ZipEntry zipEntry = new ZipEntry(path);
zipEntry.setTime(System.currentTimeMillis());
if (comment != null) {
zipEntry.setComment(comment);
}
zipEntry.setSize(0);
zipEntry.setCrc(0);
zos.putNextEntry(zipEntry);
zos.closeEntry();
}
代码示例来源:origin: apache/ignite
/**
* @param bytes Byte array to compress.
* @param compressionLevel Level of compression to encode.
* @return Compressed bytes.
* @throws IgniteCheckedException If failed.
*/
public static byte[] zip(@Nullable byte[] bytes, int compressionLevel) throws IgniteCheckedException {
try {
if (bytes == null)
return null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ZipOutputStream zos = new ZipOutputStream(bos)) {
zos.setLevel(compressionLevel);
ZipEntry entry = new ZipEntry("");
try {
entry.setSize(bytes.length);
zos.putNextEntry(entry);
zos.write(bytes);
}
finally {
zos.closeEntry();
}
}
return bos.toByteArray();
}
catch (Exception e) {
throw new IgniteCheckedException(e);
}
}
代码示例来源:origin: pxb1988/dex2jar
@Override
public void closeEntry() throws IOException {
ZipEntry delayedEntry = this.delayedEntry;
if (delayedEntry != null) {
AccessBufByteArrayOutputStream delayedOutputStream = this.delayedOutputStream;
byte[] buf = delayedOutputStream.getBuf();
int size = delayedOutputStream.size();
delayedEntry.setSize(size);
delayedEntry.setCompressedSize(size);
crc.reset();
crc.update(buf, 0, size);
delayedEntry.setCrc(crc.getValue());
super.putNextEntry(delayedEntry);
super.write(buf, 0, size);
this.delayedEntry = null;
delayedOutputStream.reset();
}
super.closeEntry();
}
代码示例来源:origin: org.apache.ant/ant
private void addFile(ZipOutputStream output, File file, String prefix,
boolean compress) throws IOException {
//Make sure file exists
if (!file.exists()) {
return;
}
ZipEntry entry = new ZipEntry(getEntryName(file, prefix));
entry.setTime(file.lastModified());
entry.setSize(file.length());
if (!compress) {
entry.setCrc(calcChecksum(file));
}
addToOutputStream(output, Files.newInputStream(file.toPath()), entry);
}
代码示例来源:origin: iBotPeaches/Apktool
crc.update(data);
entry = new ZipEntry("resources.arsc");
entry.setSize(data.length);
entry.setCrc(crc.getValue());
out.putNextEntry(entry);
CRC32 manifestCrc = new CRC32();
manifestCrc.update(manifest);
entry.setSize(manifest.length);
entry.setCompressedSize(-1);
entry.setCrc(manifestCrc.getValue());
代码示例来源:origin: redisson/redisson
zipEntry.setSize(0);
zipEntry.setCrc(0);
代码示例来源:origin: syncany/syncany
@Override
public void write(Chunk chunk) throws IOException {
size += chunk.getSize();
ZipEntry entry = new ZipEntry(StringUtil.toHex(chunk.getChecksum()));
entry.setSize(chunk.getSize());
zipOut.putNextEntry(entry);
zipOut.write(chunk.getContent(), 0, chunk.getSize());
zipOut.closeEntry();
}
代码示例来源: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: zeroturnaround/zt-zip
/**
* Create new Zip entry and fill it with associated with file meta-info
*
* @param name Zip entry name
* @param file source File
* @return newly created Zip entry
*/
static ZipEntry fromFile(String name, File file) {
ZipEntry zipEntry = new ZipEntry(name);
if (!file.isDirectory()) {
zipEntry.setSize(file.length());
}
zipEntry.setTime(file.lastModified());
ZTFilePermissions permissions = ZTFilePermissionsUtil.getDefaultStategy().getPermissions(file);
if (permissions != null) {
ZipEntryUtil.setZTFilePermissions(zipEntry, permissions);
}
return zipEntry;
}
内容来源于网络,如有侵权,请联系作者删除!