本文整理汇总了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;
}
示例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();
}
示例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();
}
}
示例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();
}
示例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.");
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}