當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipArchiveEntry.setTime方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setTime方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipArchiveEntry.setTime方法的具體用法?Java ZipArchiveEntry.setTime怎麽用?Java ZipArchiveEntry.setTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.zip.ZipArchiveEntry的用法示例。


在下文中一共展示了ZipArchiveEntry.setTime方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: filterZipEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private ZipArchiveEntry filterZipEntry(ZipArchiveEntry entry)
{
    // Set times
    entry.setCreationTime(FileTime.fromMillis(DEFAULT_ZIP_TIMESTAMP));
    entry.setLastAccessTime(FileTime.fromMillis(DEFAULT_ZIP_TIMESTAMP));
    entry.setLastModifiedTime(FileTime.fromMillis(DEFAULT_ZIP_TIMESTAMP));
    entry.setTime(DEFAULT_ZIP_TIMESTAMP);
    // Remove extended timestamps
    for (ZipExtraField field : entry.getExtraFields())
    {
        if (field instanceof X5455_ExtendedTimestamp)
        {
            entry.removeExtraField(field.getHeaderId());
        }
    }
    return entry;
}
 
開發者ID:Zlika,項目名稱:reproducible-build-maven-plugin,代碼行數:18,代碼來源:ZipStripper.java

示例2: sendCompressedDirectory

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@Override
protected void sendCompressedDirectory(MCRPath file, BasicFileAttributes attrs, ZipArchiveOutputStream container)
    throws IOException {
    ZipArchiveEntry entry = new ZipArchiveEntry(getFilename(file) + "/");
    entry.setTime(attrs.lastModifiedTime().toMillis());
    container.putArchiveEntry(entry);
    container.closeArchiveEntry();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:9,代碼來源:MCRZipServlet.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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.release();
		rw.dispose();
	}
	return success;
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:64,代碼來源:CompressionUtils.java

示例8: testExtractZipFilePreservesExecutePermissionsAndModificationTime

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@Test
public void testExtractZipFilePreservesExecutePermissionsAndModificationTime()
    throws InterruptedException, IOException {

  // getFakeTime returs time with some non-zero millis. By doing division and multiplication by
  // 1000 we get rid of that.
  final long time = ZipConstants.getFakeTime() / 1000 * 1000;

  // Create a simple zip archive using apache's commons-compress to store executable info.
  try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
    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);
    entry.setTime(time);
    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.
  Path extractFolder = tmpFolder.newFolder();
  ImmutableList<Path> result =
      ArchiveFormat.ZIP
          .getUnarchiver()
          .extractArchive(
              new DefaultProjectFilesystemFactory(),
              zipFile.toAbsolutePath(),
              extractFolder.toAbsolutePath(),
              ExistingFileMode.OVERWRITE);
  Path exe = extractFolder.toAbsolutePath().resolve("test.exe");
  assertTrue(Files.exists(exe));
  assertThat(Files.getLastModifiedTime(exe).toMillis(), Matchers.equalTo(time));
  assertTrue(Files.isExecutable(exe));
  assertEquals(ImmutableList.of(extractFolder.resolve("test.exe")), result);
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:38,代碼來源:UnzipTest.java

示例9: addToZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
public void addToZip(NodeRef node, ZipArchiveOutputStream out, boolean noaccent, String path) throws IOException {
	QName nodeQnameType = this.nodeService.getType(node);

	// Special case : links
	if (this.dictionaryService.isSubClass(nodeQnameType, ApplicationModel.TYPE_FILELINK)) {
		NodeRef linkDestinationNode = (NodeRef) nodeService.getProperty(node, ContentModel.PROP_LINK_DESTINATION);
		if (linkDestinationNode == null) {
			return;
		}

		// Duplicate entry: check if link is not in the same space of the link destination
		if (nodeService.getPrimaryParent(node).getParentRef().equals(nodeService.getPrimaryParent(linkDestinationNode).getParentRef())) {
			return;
		}

		nodeQnameType = this.nodeService.getType(linkDestinationNode);
		node = linkDestinationNode;
	}

	String nodeName = (String) nodeService.getProperty(node, ContentModel.PROP_NAME);
	nodeName = noaccent ? unAccent(nodeName) : nodeName;

	if (this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_CONTENT)) {
		ContentReader reader = contentService.getReader(node, ContentModel.PROP_CONTENT);
		if (reader != null) {
			InputStream is = reader.getContentInputStream();

			String filename = path.isEmpty() ? nodeName : path + '/' + nodeName;

			ZipArchiveEntry entry = new ZipArchiveEntry(filename);
			entry.setTime(((Date) nodeService.getProperty(node, ContentModel.PROP_MODIFIED)).getTime());

			entry.setSize(reader.getSize());
			out.putArchiveEntry(entry);

			byte buffer[] = new byte[BUFFER_SIZE];
			while (true) {
				int nRead = is.read(buffer, 0, buffer.length);
				if (nRead <= 0) {
					break;
				}

				out.write(buffer, 0, nRead);
			}
			is.close();
			out.closeArchiveEntry();
		}
		else {
			logger.warn("Could not read : "	+ nodeName + "content");
		}
	}
	else if(this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_FOLDER) 
			&& !this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_SYSTEM_FOLDER)) {
		List<ChildAssociationRef> children = nodeService
				.getChildAssocs(node);
		if (children.isEmpty()) {
			String folderPath = path.isEmpty() ? nodeName + '/' : path + '/' + nodeName + '/';
			out.putArchiveEntry(new ZipArchiveEntry(new ZipEntry(folderPath)));
		} else {
			for (ChildAssociationRef childAssoc : children) {
				NodeRef childNodeRef = childAssoc.getChildRef();

				addToZip(childNodeRef, out, noaccent,
						path.isEmpty() ? nodeName : path + '/' + nodeName);
			}
		}
	} else {
		logger.info("Unmanaged type: "
				+ nodeQnameType.getPrefixedQName(this.namespaceService)
				+ ", filename: " + nodeName);
	}
}
 
開發者ID:atolcd,項目名稱:alfresco-zip-and-download,代碼行數:73,代碼來源:ZipContents.java


注:本文中的org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。