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


Java ZipOutputStream类代码示例

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


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

示例1: zipFile

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
@Override
protected void zipFile(File file, ZipOutputStream zOut, String vPath, int mode) throws IOException {
    if (vPath.equals(layer)) {
        System.setProperty("CslJar", Boolean.TRUE.toString());
        try {
            // Create a tempfile and trick it!
            InputStream is = new FileInputStream(file);
            String modifiedLayer = getModifiedLayer(is);
            if (modifiedLayer != null) {
                File tmpFile = File.createTempFile("csl", "tmp"); // NOI18N
                BufferedWriter w = new BufferedWriter(new FileWriter(tmpFile));
                w.write(modifiedLayer);
                w.flush();
                w.close();
                // Note - we're passing the temp file instead of the "real" layer file
                super.zipFile(tmpFile, zOut, vPath, mode);
                // Remove the tmpfile
                tmpFile.delete();
                return;
            }
        } finally {
            System.setProperty("CslJar", Boolean.FALSE.toString());
        }
    }
    super.zipFile(file, zOut, vPath, mode);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CslJar.java

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

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

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

示例5: zipFile

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
@Override
protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode) throws IOException
{
    if (vPath.startsWith("META-INF/"))
    {
        if (!vPath.equals("META-INF/"+applicationName+".crcver"))
        {
            super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode);
        }
    }
    else
    {
        crcInputStream.resetStream(is);
        super.zipFile(crcInputStream, zOut, vPath, lastModified, fromArchive, mode);
        fileChecksums.add(new FileChecksum(vPath, crcInputStream.getCrcValue()));
    }

}
 
开发者ID:goldmansachs,项目名称:reladomo,代码行数:19,代码来源:JarVersionCreator.java

示例6: canDecompressZipFile

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
@Test
public void canDecompressZipFile() {
    try {
        compressedFile = Files.createTempFile(ARCHIVE_PREFIX, ".zip");
        try (final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(
                    new BufferedOutputStream(new FileOutputStream(compressedFile.toFile())))) {
            // Deflated is the default compression method
            zipDirectory(testDir, outputStream, ZipOutputStream.DEFLATED);
        }

        ExtractionTools.decompressFile(
                compressedFile.toFile(),
                decompressDestination.toFile(),
                CompressionType.Zip,
                null);

        assertEquals(getFileNames(testDir), getFileNames(decompressDestination));
    } catch (final IOException e) {
        fail(e.getMessage());
    }
}
 
开发者ID:awslabs,项目名称:aws-codepipeline-plugin-for-jenkins,代码行数:22,代码来源:ExtractionToolsTest.java

示例7: canDecompressZipFileWithStoredCompressionMethod

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
@Test
public void canDecompressZipFileWithStoredCompressionMethod() {
    try {
        compressedFile = Files.createTempFile(ARCHIVE_PREFIX, ".zip");
        try (final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(
                    new BufferedOutputStream(new FileOutputStream(compressedFile.toFile())))) {
            zipDirectory(testDir, outputStream, ZipOutputStream.STORED);
        }

        ExtractionTools.decompressFile(
                compressedFile.toFile(),
                decompressDestination.toFile(),
                CompressionType.Zip,
                null);

        assertEquals(getFileNames(testDir), getFileNames(decompressDestination));
    } catch (final IOException e) {
        fail(e.getMessage());
    }
}
 
开发者ID:awslabs,项目名称:aws-codepipeline-plugin-for-jenkins,代码行数:21,代码来源:ExtractionToolsTest.java

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

示例9: zipFile

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
@Override
protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath,
        long lastModified, File fromArchive, int mode) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IoUtil.copy(is, baos, buf);
    struct.data = baos.toByteArray();
    struct.name = vPath;
    struct.time = lastModified;
    if (proc.process(struct) != JarProcessor.Result.DISCARD) {
        if (mode == 0)
            mode = ZipFileSet.DEFAULT_FILE_MODE;
        if (!filesOnly) {
            addParentDirs(struct.name, zOut);
        }
        super.zipFile(new ByteArrayInputStream(struct.data),
                zOut, struct.name, struct.time, fromArchive, mode);
    }
}
 
开发者ID:shevek,项目名称:jarjar,代码行数:19,代码来源:AntJarProcessor.java

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

示例11: closeZout

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
/** Close zout */
private void closeZout(final ZipOutputStream zOut, final boolean success)
    throws IOException {
    if (zOut == null) {
        return;
    }
    try {
        zOut.close();
    } catch (final IOException ex) {
        // If we're in this finally clause because of an
        // exception, we don't really care if there's an
        // exception when closing the stream. E.g. if it
        // throws "ZIP file must have at least one entry",
        // because an exception happened before we added
        // any files, then we must swallow this
        // exception. Otherwise, the error that's reported
        // will be the close() error, which is not the
        // real cause of the problem.
        if (success) {
            throw ex;
        }
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:24,代码来源:Zip.java

示例12: addDirectoryResource

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
/**
 * Add a directory entry to the archive using a specified
 * Unix-mode and the default mode for its parent directories (if
 * necessary).
 */
private void addDirectoryResource(final Resource r, String name, final String prefix,
                                  final File base, final ZipOutputStream zOut,
                                  final int defaultDirMode, final int thisDirMode)
    throws IOException {

    if (!name.endsWith("/")) {
        name = name + "/";
    }

    final int nextToLastSlash = name.lastIndexOf('/', name.length() - 2);
    if (nextToLastSlash != -1) {
        addParentDirs(base, name.substring(0, nextToLastSlash + 1),
                      zOut, prefix, defaultDirMode);
    }
    zipDir(r, zOut, prefix + name, thisDirMode,
           r instanceof ZipResource
           ? ((ZipResource) r).getExtraFields() : null);
}
 
开发者ID:apache,项目名称:ant,代码行数:24,代码来源:Zip.java

示例13: zipFile

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
/**
 * Method that gets called when adding from <code>java.io.File</code> instances.
 *
 * <p>This implementation delegates to the six-arg version.</p>
 *
 * @param file the file 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.
 * @throws IOException on error
 *
 * @since Ant 1.5.2
 */
protected void zipFile(final File file, final ZipOutputStream zOut, final String vPath,
                       final int mode)
    throws IOException {
    if (file.equals(zipFile)) {
        throw new BuildException("A zip file cannot include itself",
                                 getLocation());
    }

    try (final BufferedInputStream bIn = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
        // ZIPs store time with a granularity of 2 seconds, round up
        zipFile(bIn, zOut, vPath,
                file.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0),
                null, mode);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:29,代码来源:Zip.java

示例14: zipFile

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
/**
 * Overridden from Zip class to deal with manifests and index lists.
 * @param is the stream to read data for the entry from.  The
 * caller of the method is responsible for closing the stream.
 * @param zOut the zip output stream
 * @param vPath the name this entry shall have in the archive
 * @param lastModified last modification time for the entry.
 * @param fromArchive the original archive we are copying this
 *                    entry from, will be null if we are not copying from an archive.
 * @param mode the Unix permissions to set.
 * @throws IOException on error
 */
@Override
protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath,
                       long lastModified, File fromArchive, int mode)
    throws IOException {
    if (MANIFEST_NAME.equalsIgnoreCase(vPath))  {
        if (isFirstPass()) {
            filesetManifest(fromArchive, is);
        }
    } else if (INDEX_NAME.equalsIgnoreCase(vPath) && index) {
        logWhenWriting("Warning: selected " + archiveType
                       + " files include a " + INDEX_NAME + " which will"
                       + " be replaced by a newly generated one.",
                       Project.MSG_WARN);
    } else {
        if (index && vPath.indexOf('/') == -1) {
            rootEntries.add(vPath);
        }
        super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:33,代码来源:Jar.java

示例15: getSetPermissionsWorksForZipResources

import org.apache.tools.zip.ZipOutputStream; //导入依赖的package包/类
@Test
public void getSetPermissionsWorksForZipResources() throws IOException {
    File f = File.createTempFile("ant", ".zip");
    f.deleteOnExit();
    try (ZipOutputStream os = new ZipOutputStream(f)) {
        ZipEntry e = new ZipEntry("foo");
        os.putNextEntry(e);
        os.closeEntry();
    }

    ZipResource r = new ZipResource();
    r.setName("foo");
    r.setArchive(f);
    Set<PosixFilePermission> s =
        EnumSet.of(PosixFilePermission.OWNER_READ,
                   PosixFilePermission.OWNER_WRITE,
                   PosixFilePermission.OWNER_EXECUTE,
                   PosixFilePermission.GROUP_READ);
    PermissionUtils.setPermissions(r, s, null);
    assertEquals(s, PermissionUtils.getPermissions(r, null));
}
 
开发者ID:apache,项目名称:ant,代码行数:22,代码来源:PermissionUtilsTest.java


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