当前位置: 首页>>代码示例>>Java>>正文


Java ZipArchiveEntry.setSize方法代码示例

本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setSize方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveEntry.setSize方法的具体用法?Java ZipArchiveEntry.setSize怎么用?Java ZipArchiveEntry.setSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.compress.archivers.zip.ZipArchiveEntry的用法示例。


在下文中一共展示了ZipArchiveEntry.setSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: entryToNewName

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
 * Entry to new name.
 *
 * @param source the source
 * @param name the name
 * @return the zip archive entry
 * @throws ZipException the zip exception
 */
public static ZipArchiveEntry entryToNewName(ZipArchiveEntry source, String name) throws ZipException {
  if (source.getName().equals(name))
    return new ZipArchiveEntry(source);
  ZipArchiveEntry ret = new ZipArchiveEntry(name);
  byte[] extra = source.getExtra();
  if (extra != null) {
    ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ));
  } else {
    ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true)));
  }
  ret.setInternalAttributes(source.getInternalAttributes());
  ret.setExternalAttributes(source.getExternalAttributes());
  ret.setExtraFields(source.getExtraFields(true));
  ret.setCrc(source.getCrc());
  ret.setMethod(source.getMethod());
  ret.setSize(source.getSize());
  return ret;
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:27,代码来源:JarDelta.java

示例2: createArchiveEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
 * Use for writing streams - must specify file size in advance as well
 */
public static ArchiveEntry createArchiveEntry(String relativePath, ArchiveType archiveType, long size) {
    switch (archiveType) {
        case ZIP:
            ZipArchiveEntry zipEntry = new ZipArchiveEntry(relativePath);
            zipEntry.setSize(size);
            return zipEntry;
        case TAR:
        case TARGZ:
        case TGZ:
            TarArchiveEntry tarEntry = new TarArchiveEntry(relativePath);
            tarEntry.setSize(size);
            return tarEntry;
    }
    throw new IllegalArgumentException("Unsupported archive type: '" + archiveType + "'");
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:19,代码来源:ArchiveUtils.java

示例3: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
 * Add one file to the open zip archive stream. Drops the file if it is a directory
 * 
 * @param fileToZip
 * @param baseDir
 * @param os
 * @throws Throwable
 */
public static void zip(File fileToZip, ZipArchiveOutputStream os) throws Throwable {
	if (fileToZip.isDirectory()) return;

	byte buffer[] = new byte[BUFFER_SIZE];
	String name = fileToZip.getName();
	ZipArchiveEntry entry = new ZipArchiveEntry(fileToZip, name);
	entry.setSize(fileToZip.length());
	os.putArchiveEntry(entry);
	BufferedInputStream is = new BufferedInputStream(new FileInputStream(fileToZip), BUFFER_SIZE);
	int count;
	try {
		while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
			os.write(buffer, 0, count);
		}
	} finally {
		is.close();
	}
	os.closeArchiveEntry();
}
 
开发者ID:uom-daris,项目名称:daris,代码行数:28,代码来源:ZipUtil.java

示例4: visitEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
public void visitEntry(ApkArchiveEntry entry) throws IOException {
	super.visitEntry(entry);

	if (includedFiles.contains(entry.getFilename())) {
		return;
	}

	ZipArchiveEntry zipEntry = new ZipArchiveEntry(entry.getFilename());
	includedFiles.add(entry.getFilename());

	if (entry.getMethod() == ZipEntry.STORED) {
		zipEntry.setSize(entry.getSize());
		zipEntry.setCrc(entry.getCrc());
	}

	zaos.setMethod(entry.getMethod());

	zaos.putArchiveEntry(zipEntry);
	IOUtils.copy(entry.getInputStream(), zaos);

	zaos.closeArchiveEntry();
}
 
开发者ID:testfairy,项目名称:testfairy-jenkins-plugin,代码行数:24,代码来源:ApkArchiveWriter.java

示例5: sendCompressedFile

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
protected void sendCompressedFile(MCRPath file, BasicFileAttributes attrs, ZipArchiveOutputStream container)
    throws IOException {
    ZipArchiveEntry entry = new ZipArchiveEntry(getFilename(file));
    entry.setTime(attrs.lastModifiedTime().toMillis());
    entry.setSize(attrs.size());
    container.putArchiveEntry(entry);
    try {
        Files.copy(file, container);
    } finally {
        container.closeArchiveEntry();
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:14,代码来源:MCRZipServlet.java

示例6: sendMetadataCompressed

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
protected void sendMetadataCompressed(String fileName, byte[] content, long lastModified,
    ZipArchiveOutputStream container) throws IOException {
    ZipArchiveEntry entry = new ZipArchiveEntry(fileName);
    entry.setSize(content.length);
    entry.setTime(lastModified);
    container.putArchiveEntry(entry);
    container.write(content);
    container.closeArchiveEntry();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:11,代码来源:MCRZipServlet.java

示例7: newTailArchive

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static ArchiveEntry newTailArchive(String name, byte[] tail) {
    ZipArchiveEntry zipEntry = new ZipArchiveEntry(name);
    zipEntry.setSize(tail.length);
    zipEntry.setCompressedSize(zipEntry.getSize());
    CRC32 crc32 = new CRC32();
    crc32.update(tail);
    zipEntry.setCrc(crc32.getValue());
    return zipEntry;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:10,代码来源:LogArchiver.java

示例8: newArchive

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static ArchiveEntry newArchive(File file) throws IOException {
    ZipArchiveEntry zipEntry = new ZipArchiveEntry(file.getName());
    zipEntry.setSize(file.length());
    zipEntry.setCompressedSize(zipEntry.getSize());
    zipEntry.setCrc(FileUtils.checksumCRC32(file));
    return zipEntry;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:8,代码来源:LogArchiver.java

示例9: newStoredEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
protected ArchiveEntry newStoredEntry(String name, byte[] data) {
    ZipArchiveEntry zipEntry = new ZipArchiveEntry(name);
    zipEntry.setSize(data.length);
    zipEntry.setCompressedSize(zipEntry.getSize());
    CRC32 crc32 = new CRC32();
    crc32.update(data);
    zipEntry.setCrc(crc32.getValue());
    return zipEntry;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:10,代码来源:FoldersServiceBean.java

示例10: createEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
ArchiveEntry createEntry(long size) throws IOException {
    // TODO: How to set entry name and indexes.
    String name =  String.format(entryNamePrefix, baseNum, count++);

    switch (format) {
    case CPIO:
        CpioArchiveEntry cpioEntry = new CpioArchiveEntry(name);
        cpioEntry.setSize(size);
        cpioEntry.setTime(System.currentTimeMillis());
        return cpioEntry;
    case JAR:
        JarArchiveEntry jarEntry = new JarArchiveEntry(name);
        jarEntry.setSize(size);
        jarEntry.setTime(System.currentTimeMillis());
        return jarEntry;
    case TAR:
        TarArchiveEntry tarEntry = new TarArchiveEntry(name);
        tarEntry.setSize(size);
        tarEntry.setModTime(System.currentTimeMillis());
        return tarEntry;
    case ZIP:
        ZipArchiveEntry zipEntry = new ZipArchiveEntry(name);
        zipEntry.setSize(size);
        zipEntry.setTime(System.currentTimeMillis());
        return zipEntry;
    }

    // Normally, this code is not called because of the above switch.
    throw new IOException("Format is configured.");
}
 
开发者ID:hata,项目名称:embulk-encoder-commons-compress,代码行数:31,代码来源:CommonsCompressArchiveProvider.java

示例11: strip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
public void strip(File in, File out) throws IOException
{
    try (final ZipFile zip = new ZipFile(in);
         final ZipArchiveOutputStream zout = new ZipArchiveOutputStream(out))
    {
        final List<String> sortedNames = sortEntriesByName(zip.getEntries());
        for (String name : sortedNames)
        {
            final ZipArchiveEntry entry = zip.getEntry(name);
            // Strip Zip entry
            final ZipArchiveEntry strippedEntry = filterZipEntry(entry);
            // Strip file if required
            final Stripper stripper = getSubFilter(name);
            if (stripper != null)
            {
                // Unzip entry to temp file
                final File tmp = File.createTempFile("tmp", null);
                tmp.deleteOnExit();
                Files.copy(zip.getInputStream(entry), tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);
                final File tmp2 = File.createTempFile("tmp", null);
                tmp2.deleteOnExit();
                stripper.strip(tmp, tmp2);
                final byte[] fileContent = Files.readAllBytes(tmp2.toPath());
                strippedEntry.setSize(fileContent.length);
                zout.putArchiveEntry(strippedEntry);
                zout.write(fileContent);
                zout.closeArchiveEntry();
            }
            else
            {
                // Copy the Zip entry as-is
                zout.addRawArchiveEntry(strippedEntry, zip.getRawInputStream(entry));
            }
        }
    }
}
 
开发者ID:Zlika,项目名称:reproducible-build-maven-plugin,代码行数:38,代码来源:ZipStripper.java

示例12: writeJarEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static void writeJarEntry(JarArchiveOutputStream jaos, String name, byte[] data) throws IOException {
    ZipArchiveEntry entry = new JarArchiveEntry(name);
    entry.setSize(data.length);
    jaos.putArchiveEntry(entry);
    jaos.write(data);
    jaos.closeArchiveEntry();
}
 
开发者ID:offbynull,项目名称:coroutines,代码行数:8,代码来源:TestUtils.java

示例13: createArchiveEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
public ArchiveEntry createArchiveEntry(String targetPath, long targetSize, byte[] targetBytes) {
    ZipArchiveEntry zipEntry = new ZipArchiveEntry(targetPath);
    zipEntry.setSize(targetSize);
    zipEntry.setMethod(ZipEntry.STORED);
    if (targetBytes != null) {
        zipEntry.setCrc(crc32Checksum(targetBytes));
    }
    return zipEntry;
}
 
开发者ID:trustsystems,项目名称:elfinder-java-connector,代码行数:11,代码来源:ZipArchiver.java

示例14: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
 * Zips the contents of the tree at the (optionally) specified revision and the (optionally) specified basepath to the supplied outputstream.
 * 
 * @param repository
 * @param basePath
 *            if unspecified, entire repository is assumed.
 * @param objectId
 *            if unspecified, HEAD is assumed.
 * @param os
 * @return true if repository was successfully zipped to supplied output stream
 */
public static boolean zip(Repository repository, String basePath, String objectId, OutputStream os) {
	RevCommit commit = JGitUtils.getCommit(repository, objectId);
	if (commit == null) {
		return false;
	}
	boolean success = false;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	try {
		tw.reset();
		tw.addTree(commit.getTree());
		ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
		zos.setComment("Generated by Gitblit");
		if (!StringUtils.isEmpty(basePath)) {
			PathFilter f = PathFilter.create(basePath);
			tw.setFilter(f);
		}
		tw.setRecursive(true);
		MutableObjectId id = new MutableObjectId();
		ObjectReader reader = tw.getObjectReader();
		long modified = commit.getAuthorIdent().getWhen().getTime();
		while (tw.next()) {
			FileMode mode = tw.getFileMode(0);
			if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
				continue;
			}
			tw.getObjectId(id, 0);

			ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
			entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
			entry.setComment(commit.getName());
			entry.setUnixMode(mode.getBits());
			entry.setTime(modified);
			zos.putArchiveEntry(entry);

			ObjectLoader ldr = repository.open(id);
			ldr.copyTo(zos);
			zos.closeArchiveEntry();
		}
		zos.finish();
		success = true;
	} catch (IOException e) {
		error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
	} finally {
		tw.close();
		rw.close();
		rw.dispose();
	}
	return success;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:62,代码来源:CompressionUtils.java

示例15: testExtractZipFilePreservesExecutePermissions

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Test
public void testExtractZipFilePreservesExecutePermissions() throws IOException {

  // Create a simple zip archive using apache's commons-compress to store executable info.
  try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile)) {
    ZipArchiveEntry entry = new ZipArchiveEntry("test.exe");
    entry.setUnixMode((int) MorePosixFilePermissions.toMode(
        PosixFilePermissions.fromString("r-x------")));
    entry.setSize(DUMMY_FILE_CONTENTS.length);
    entry.setMethod(ZipEntry.STORED);
    zip.putArchiveEntry(entry);
    zip.write(DUMMY_FILE_CONTENTS);
    zip.closeArchiveEntry();
  }

  // Now run `Unzip.extractZipFile` on our test zip and verify that the file is executable.
  File extractFolder = tmpFolder.newFolder();
  ImmutableList<Path> result = Unzip.extractZipFile(
      zipFile.toPath().toAbsolutePath(),
      extractFolder.toPath().toAbsolutePath(),
      false);
  File exe = new File(extractFolder.getAbsoluteFile() + "/test.exe");
  assertTrue(exe.exists());
  assertTrue(exe.canExecute());
  assertEquals(
      ImmutableList.of(
          extractFolder.toPath().resolve("test.exe")),
      result);

}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:31,代码来源:UnzipTest.java


注:本文中的org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。