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


Java ZipOutputStream.putNextEntry方法代码示例

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


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

示例3: createZipOutputStream

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
@Test
@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0, concurrency = 1)
public void createZipOutputStream() throws Exception {
	final String FILE_NAME = "custom/output/zipOutputStream.zip";
	//
	ZipOutputStream value = IoHelper.createZipOutputStream(FILE_NAME);
	System.out.println(value);
	assertNotNull(value);
	//
	String fileName = "custom/output/test.log";
	byte[] contents = IoHelper.read(fileName);
	ZipEntry zipEntry = new ZipEntry(fileName);
	value.putNextEntry(zipEntry);
	value.write(contents);

	// 須加 close,強制寫入
	IoHelper.close(value);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:19,代码来源:IoHelperTest.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: zip

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
private void zip(ZipOutputStream out, File f, String base) throws Exception {
    if (f.isDirectory()) {
        File[] fl = f.listFiles();
        out.putNextEntry(new ZipEntry(base + File.separator));
        base = base.length() == 0 ? "" : base + File.separator;
        for (File fl1 : fl) {
            zip(out, fl1, base + fl1.getName());
        }
    } else {
        out.putNextEntry(new ZipEntry(base));
        FileInputStream in = new FileInputStream(f);
        int b;
        while ((b = in.read()) != -1) {
            out.write(b);
        }
        in.close();
    }
}
 
开发者ID:hou80houzhu,项目名称:rocserver,代码行数:19,代码来源:Jile.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()) {
				// 如果是文件,则调用文件压缩方法
				FileUtils.zipFilesToZipFile(dirPath, files[i], zouts);
			} else {
				// 如果是目录,则递归调用
				FileUtils.zipDirectoryToZipFile(dirPath, files[i], zouts);
			}
		}
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:35,代码来源:FileUtils.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()) {
                // 如果是文件,则调用文件压缩方法
                FileHelper.zipFilesToZipFile(dirPath, files[i], zouts);
            } else {
                // 如果是目录,则递归调用
                FileHelper.zipDirectoryToZipFile(dirPath, files[i],zouts);
            }
        }

    }

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

示例8: zipFile

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * <p>
 * 递归压缩文件
 * </p>
 *
 * @param parentFile parentFile
 * @param basePath basePath
 * @param zos zos
 */
private static void zipFile(File parentFile, String basePath, ZipOutputStream zos) throws Exception {
    File[] files = new File[0];
    if (parentFile.isDirectory()) {
        files = parentFile.listFiles();
    } else {
        files = new File[1];
        files[0] = parentFile;
    }
    String pathName;
    InputStream is;
    BufferedInputStream bis;
    byte[] cache = new byte[CACHE_SIZE];
    for (File file : files) {
        if (file.isDirectory()) {
            pathName = file.getPath().substring(basePath.length() + 1) + "/";
            zos.putNextEntry(new ZipEntry(pathName));
            zipFile(file, basePath, zos);
        } else {
            pathName = file.getPath().substring(basePath.length() + 1);
            is = new FileInputStream(file);
            bis = new BufferedInputStream(is);
            zos.putNextEntry(new ZipEntry(pathName));
            int nRead = 0;
            while ((nRead = bis.read(cache, 0, CACHE_SIZE)) != -1) {
                zos.write(cache, 0, nRead);
            }
            bis.close();
            is.close();
        }
    }
}
 
开发者ID:JoyLau,项目名称:joylau-springboot-daemon-windows,代码行数:41,代码来源:ZipUtils.java

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

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

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

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

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

示例14: zipDir

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

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