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


Java ZipEntry.setTime方法代码示例

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


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

示例1: writeTo

import org.apache.tools.zip.ZipEntry; //导入方法依赖的package包/类
public void writeTo(OutputStream out) throws IOException {
    final Set<String> filenames = new HashSet<String>();
    final ZipOutputStream zipout = new ZipOutputStream(out);
    for (IFile f : container.getFiles()) {
        assertNoAbsolutePath(f);
        assertNoDuplicates(filenames, f);
        ZipEntry entry = new ZipEntry(f.getLocalPath());
        entry.setTime(f.getLastModified());
        if (f.getPermissions() != IFile.UNDEF_PERMISSIONS) {
            entry.setUnixMode(f.getPermissions());
        }
        zipout.putNextEntry(entry);
        f.writeTo(zipout);
        zipout.closeEntry();
    }
    zipout.finish();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:Files.java

示例2: zip

import org.apache.tools.zip.ZipEntry; //导入方法依赖的package包/类
public static void zip(String path, List<File> files) throws IOException {
	ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(   
			new FileOutputStream(path), 1024));   
	for(File f : files) {
		String zipName = f.getName();
		if(!f.getName().contains(".png")) { 
			zipName = f.getName() + ".xml"; 
		}
		ZipEntry ze = new ZipEntry(zipName);
		ze.setTime(f.lastModified());
	    DataInputStream dis = new DataInputStream(new BufferedInputStream(   
	                new FileInputStream(f)));   
        zos.putNextEntry(ze);   
        int c;   
        while ((c = dis.read()) != -1) {   
            zos.write(c);   
        }   
	}
	zos.setEncoding("gbk");    
       zos.closeEntry();   
       zos.close();  
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:23,代码来源:ZipUtil.java

示例3: visitFile

import org.apache.tools.zip.ZipEntry; //导入方法依赖的package包/类
private void visitFile(FileCopyDetails fileDetails) {
    try {
        ZipEntry archiveEntry = new ZipEntry(fileDetails.getRelativePath().getPathString());
        archiveEntry.setTime(fileDetails.getLastModified());
        archiveEntry.setUnixMode(UnixStat.FILE_FLAG | fileDetails.getMode());
        zipOutStr.putNextEntry(archiveEntry);
        fileDetails.copyTo(zipOutStr);
        zipOutStr.closeEntry();
    } catch (Exception e) {
        throw new GradleException(String.format("Could not add %s to ZIP '%s'.", fileDetails, zipFile), e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:13,代码来源:ZipCopyAction.java

示例4: visitDir

import org.apache.tools.zip.ZipEntry; //导入方法依赖的package包/类
private void visitDir(FileCopyDetails dirDetails) {
    try {
        // Trailing slash in name indicates that entry is a directory
        ZipEntry archiveEntry = new ZipEntry(dirDetails.getRelativePath().getPathString() + '/');
        archiveEntry.setTime(dirDetails.getLastModified());
        archiveEntry.setUnixMode(UnixStat.DIR_FLAG | dirDetails.getMode());
        zipOutStr.putNextEntry(archiveEntry);
        zipOutStr.closeEntry();
    } catch (Exception e) {
        throw new GradleException(String.format("Could not add %s to ZIP '%s'.", dirDetails, zipFile), e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:13,代码来源:ZipCopyAction.java

示例5: zipDir

import org.apache.tools.zip.ZipEntry; //导入方法依赖的package包/类
/**
 * Add a directory to the zip stream.
 * @param dir  the directory to add to the archive
 * @param zOut the stream to write to
 * @param vPath the name this entry shall have in the archive
 * @param mode the Unix permissions to set.
 * @param extra ZipExtraFields to add
 * @throws IOException on error
 * @since Ant 1.8.0
 */
protected void zipDir(final Resource dir, final ZipOutputStream zOut, final String vPath,
                      final int mode, final ZipExtraField[] extra)
    throws IOException {
    if (doFilesonly) {
        logWhenWriting("skipping directory " + vPath
                       + " for file-only archive",
                       Project.MSG_VERBOSE);
        return;
    }
    if (addedDirs.get(vPath) != null) {
        // don't add directories we've already added.
        // no warning if we try, it is harmless in and of itself
        return;
    }

    logWhenWriting("adding directory " + vPath, Project.MSG_VERBOSE);
    addedDirs.put(vPath, vPath);

    if (!skipWriting) {
        final ZipEntry ze = new ZipEntry(vPath);

        // ZIPs store time with a granularity of 2 seconds, round up
        final int millisToAdd = roundUp ? ROUNDUP_MILLIS : 0;

        if (fixedModTime != null) {
            ze.setTime(modTimeMillis);
        } else if (dir != null && dir.isExists()) {
            ze.setTime(dir.getLastModified() + millisToAdd);
        } else {
            ze.setTime(System.currentTimeMillis() + millisToAdd);
        }
        ze.setSize(0);
        ze.setMethod(ZipEntry.STORED);
        // This is faintly ridiculous:
        ze.setCrc(EMPTY_CRC);
        ze.setUnixMode(mode);

        if (extra != null) {
            ze.setExtraFields(extra);
        }

        zOut.putNextEntry(ze);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:55,代码来源:Zip.java

示例6: addEntry

import org.apache.tools.zip.ZipEntry; //导入方法依赖的package包/类
/**
 * 向 zip输出流 增加文件实体
 * 
 * @param zipEntryName
 *            zip中文件实体名称
 * @param file
 *            物理文件
 * @param zos
 *            ZipOutputStream
 * @param useSameDir
 *            值为 false 时,保存原有目录结构,zipEntryName 将被忽略
 * @throws IOException
 *             IO异常
 */
private static void addEntry(String zipEntryName, File file, ZipOutputStream zos,
        Boolean useSameDir) throws IOException {

    String entryName = zipEntryName;

    if (file.isDirectory()) {

        // 使用1层目录才可以用别名,否则还是原始文件名,且忽略目录
        if (useSameDir) {
            // File[] fl = file.listFiles();
            // for (int i = 0; i < fl.length; i++) {
            // addEntry(entryName,fl[i], zos,useSameDir);
            // }
        } else {
            entryName = getDirectoryPath(file) + "/";
            logger.debug("add zip entry directory: " + entryName);
            zos.putNextEntry(new ZipEntry(entryName));

            File[] fl = file.listFiles();
            for (int i = 0; i < fl.length; i++) {
                addEntry(entryName, fl[i], zos, useSameDir);
            }
        }

    } else {

        byte[] buf = new byte[BUFFER_SIZE];

        FileInputStream in = new FileInputStream(file);

        if (useSameDir) {
            entryName = zipEntryName;
        } else {
            entryName = getFilePath(file);
            // entryName = new File(entryName).getName();
        }

        ZipEntry entry = new ZipEntry(entryName);
        entry.setTime(file.lastModified());

        logger.debug("add zip entry file: " + entryName);

        zos.putNextEntry(entry);
        int len;
        while ((len = in.read(buf)) > 0) {
            zos.write(buf, 0, len);
        }
        in.close();
        zos.flush();
    }

    zos.closeEntry();
}
 
开发者ID:jiucai,项目名称:appframework,代码行数:68,代码来源:ZipFileUtil.java


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