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


Java ZipOutputStream.closeEntry方法代码示例

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


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

示例1: writeTo

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的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.ZipOutputStream; //导入方法依赖的package包/类
/**
 * <p>
 * 压缩文件
 * </p>
 *
 * @param sourceFolder 压缩文件夹
 * @param zipFilePath 压缩文件输出路径
 */
public static void zip(String sourceFolder, String zipFilePath) throws Exception {
    OutputStream out = new FileOutputStream(zipFilePath);
    BufferedOutputStream bos = new BufferedOutputStream(out);
    ZipOutputStream zos = new ZipOutputStream(bos);
    // 解决中文文件名乱码
    zos.setEncoding(CHINESE_CHARSET);
    File file = new File(sourceFolder);
    String basePath = null;
    if (file.isDirectory()) {
        basePath = file.getPath();
    } else {
        basePath = file.getParent();
    }
    zipFile(file, basePath, zos);
    zos.closeEntry();
    zos.close();
    bos.close();
    out.close();
}
 
开发者ID:JoyLau,项目名称:joylau-springboot-daemon-windows,代码行数:28,代码来源:ZipUtils.java

示例3: doZip

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
private static void doZip(ZipOutputStream zos, String filePath, String pathName) throws IOException {
    File file2zip = new File(filePath);
    if (file2zip.isFile()) {
        zos.putNextEntry(new org.apache.tools.zip.ZipEntry(pathName + file2zip.getName()));
        IOUtils.copy(new FileInputStream(file2zip.getAbsolutePath()), zos);
        zos.closeEntry();
    } else {
        File[] files = file2zip.listFiles();
        if (files != null) {
            for (File f : files) {
                if (f.isDirectory()) {
                    doZip(zos, f.getAbsolutePath(), pathName + f.getName() + File.separator);
                } else {
                    zos.putNextEntry(new org.apache.tools.zip.ZipEntry(pathName + File.separator + f.getName()));
                    IOUtils.copy(new FileInputStream(f.getAbsolutePath()), zos);
                    zos.closeEntry();
                }
            }
        }
    }
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:22,代码来源:ZipUtils.java

示例4: zip

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的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

示例5: zipDirectoryToZipFile

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * 将目录压缩到ZIP输出流
 *
 * @param dirPath 目录路径
 * @param fileDir 文件信息
 * @param zouts   输出流
 */
public static void zipDirectoryToZipFile(String dirPath, File fileDir, ZipOutputStream zouts) {
	if (fileDir.isDirectory()) {
		File[] files = fileDir.listFiles();
		// 空的文件夹
		if (files.length == 0) {
			// 目录信息
			ZipEntry entry = new ZipEntry(getEntryName(dirPath, fileDir));
			try {
				zouts.putNextEntry(entry);
				zouts.closeEntry();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return;
		}

		for (int i = 0; i < files.length; i++) {
			if (files[i].isFile()) {
				// 如果是文件,则调用文件压缩方法
				FileUtils.zipFilesToZipFile(dirPath, files[i], zouts);
			} else {
				// 如果是目录,则递归调用
				FileUtils.zipDirectoryToZipFile(dirPath, files[i], zouts);
			}
		}
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:35,代码来源:FileUtils.java

示例6: zipDirectoryToZipFile

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * 将目录压缩到ZIP输出流
 * @param dirPath 目录路径
 * @param fileDir 文件信息
 * @param zouts 输出流
 */
public static void zipDirectoryToZipFile(String dirPath, File fileDir,ZipOutputStream zouts) {
    if (fileDir.isDirectory()) {
        File[] files = fileDir.listFiles();
        // 空的文件夹
        if (files.length == 0) {
            // 目录信息
            ZipEntry entry = new ZipEntry(getEntryName(dirPath, fileDir));
            try {
                zouts.putNextEntry(entry);
                zouts.closeEntry();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return;
        }

        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile()) {
                // 如果是文件,则调用文件压缩方法
                FileHelper.zipFilesToZipFile(dirPath, files[i], zouts);
            } else {
                // 如果是目录,则递归调用
                FileHelper.zipDirectoryToZipFile(dirPath, files[i],zouts);
            }
        }

    }

}
 
开发者ID:liuxx001,项目名称:bird-java,代码行数:36,代码来源:FileHelper.java

示例7: zipDirectoryToZipFile

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * 将目录压缩到ZIP输出流
 *
 * @param dirPath 目录路径
 * @param fileDir 文件信息
 * @param zouts   输出流
 */
public static void zipDirectoryToZipFile(String dirPath, File fileDir, ZipOutputStream zouts) {
    if (fileDir.isDirectory()) {
        File[] files = fileDir.listFiles();
        // 空的文件夹
        if (files.length == 0) {
            // 目录信息
            ZipEntry entry = new ZipEntry(getEntryName(dirPath, fileDir));
            try {
                zouts.putNextEntry(entry);
                zouts.closeEntry();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return;
        }

        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile()) {
                // 如果是文件,则调用文件压缩方法
                FileUtils.zipFilesToZipFile(dirPath, files[i], zouts);
            } else {
                // 如果是目录,则递归调用
                FileUtils.zipDirectoryToZipFile(dirPath, files[i], zouts);
            }
        }
    }
}
 
开发者ID:ansafari,项目名称:melon,代码行数:35,代码来源:FileUtils.java

示例8: zipDirectoryToZipFile

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * 将目录压缩到ZIP输出流
 * @param dirPath 目录路径
 * @param fileDir 文件信息
 * @param zouts 输出流
 */
public static void zipDirectoryToZipFile(String dirPath, File fileDir,
		ZipOutputStream zouts) {
	if (fileDir.isDirectory()) {
		File[] files = fileDir.listFiles();
		// 空的文件夹
		if (files.length == 0) {
			// 目录信息
			ZipEntry entry = new ZipEntry(getEntryName(dirPath, fileDir));
			try {
				zouts.putNextEntry(entry);
				zouts.closeEntry();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return;
		}

		for (int i = 0; i < files.length; i++) {
			if (files[i].isFile()) {
				// 如果是文件,则调用文件压缩方法
				FileUtils
						.zipFilesToZipFile(dirPath, files[i], zouts);
			} else {
				// 如果是目录,则递归调用
				FileUtils.zipDirectoryToZipFile(dirPath, files[i],
						zouts);
			}
		}

	}

}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:39,代码来源:FileUtils.java

示例9: antzipFiles

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * @param file
 *            压缩文件
 * @param zipOutput
 *            ZipOutputStream
 * @param pathName
 *            相对路径
 * @throws Exception
 *             异常
 */
private static void antzipFiles(File file, ZipOutputStream zipOutput,
        String pathName) throws Exception {
    String fileName = pathName + file.getName();
    if (file.isDirectory()) {
        fileName = fileName + "/";
        zipOutput.putNextEntry(new ZipEntry(fileName));
        String fileNames[] = file.list();
        if (fileNames != null) {
            for (int i = 0; i < fileNames.length; i++) {
                antzipFiles(new File(file, fileNames[i]), zipOutput,
                        fileName);
            }
            zipOutput.closeEntry();
        }
    } else {
        ZipEntry jarEntry = new ZipEntry(fileName);
        BufferedInputStream in = new BufferedInputStream(
                new FileInputStream(file));
        zipOutput.putNextEntry(jarEntry);

        byte[] buf = new byte[bufSize];
        int len;
        while ((len = in.read(buf)) >= 0) {
            zipOutput.write(buf, 0, len);
        }
        in.close();
        zipOutput.closeEntry();
    }
}
 
开发者ID:545473750,项目名称:zswxsqxt,代码行数:40,代码来源:ZipFileUtils.java

示例10: zip

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/** 递归压缩文件进zip文件流 */
private void zip(ZipOutputStream zos, File file, String base) throws IOException {
    if (file.isDirectory()) { // 目录时
        File[] files = file.listFiles();
        if (null != files && files.length > 0) {
            for (File f : files) {
                zip(zos, f, base + "/" + f.getName()); // 递归
            }
        } else {
            zos.putNextEntry(new ZipEntry(base + "/")); // 加入目录条目
            zos.closeEntry();
        }
    } else {
        zos.putNextEntry(new ZipEntry(base)); // 加入文件条目
        FileInputStream fis = new FileInputStream(file); // 创建文件输入流
        try {
            int count; // 读取计数
            byte[] buffer = new byte[Config.BUFFER_LENGTH]; // 缓冲字节数组
            /* 写入zip输出流 */
            while ((count = fis.read(buffer)) != -1) {
                zos.write(buffer, 0, count);
            }
        } finally {
            zos.flush();
            zos.closeEntry();
            fis.close();
        }
    }
}
 
开发者ID:taugin,项目名称:cim,代码行数:30,代码来源:HttpDownHandler.java

示例11: zip

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * zip方法对文件或者文件夹进行压缩
 * 
 * @param zipstringPath
 *            为要压缩的文件或者文件夹路径
 * @param zipFileName
 *            为压缩之后生成的文件名
 */
public void zip(String zipstringPath, String zipFileName) throws Exception {
	try {

		byte[] buf = new byte[1024];
		File zipPath = new File(zipstringPath);
		int filelen = zipPath.listFiles().length;
		String[] filenames = new String[filelen];
		try {
			File[] files = zipPath.listFiles();
			for (int i = 0; i < filelen; i++) {
				filenames[i] = zipPath.getPath() + File.separator
						+ files[i].getName();
			}
			ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
					zipFileName));
			for (int i = 0; i < filenames.length; i++) {
				FileInputStream in = new FileInputStream(filenames[i]);
				out.putNextEntry(new ZipEntry(files[i].getName()));
				int len;
				while ((len = in.read(buf)) > 0) {
					out.write(buf, 0, len);
				}
				out.closeEntry();
				in.close();
			}

			out.close();
		} catch (IOException e) {
			System.out.println(e);
		}

	} catch (Exception ex) {
		ex.printStackTrace(System.out);

	}
}
 
开发者ID:easyjf,项目名称:easyjweb,代码行数:45,代码来源:ZipUtils.java

示例12: addEntry

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的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.ZipOutputStream.closeEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。