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


Java ZipArchiveOutputStream类代码示例

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


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

示例1: writeArchivedLogTailToStream

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException {
    if (!logFile.exists()) {
        throw new FileNotFoundException();
    }

    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream);
    zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
    zipOutputStream.setEncoding(ZIP_ENCODING);

    byte[] content = getTailBytes(logFile);

    ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content);
    zipOutputStream.putArchiveEntry(archiveEntry);
    zipOutputStream.write(content);

    zipOutputStream.closeArchiveEntry();
    zipOutputStream.close();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:LogArchiver.java

示例2: compressDirectoryToZipfile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
private static void compressDirectoryToZipfile(String rootDir, String sourceDir, ZipArchiveOutputStream out) throws IOException {
    File[] files = new File(sourceDir).listFiles();
    assert files != null;
    for (File file : files) {
        if (file.isDirectory()) {
            compressDirectoryToZipfile(rootDir, sourceDir + File.separator + file.getName(), out);
        } else {
            ZipArchiveEntry entry = new ZipArchiveEntry(file.getAbsolutePath().substring(rootDir.length() + 1));
            if (Host.isUnix()) {
                if (file.canExecute()) {
                    //set -rwxr-xr-x
                    entry.setUnixMode(0100755);
                } else {
                    //set -rw-r--r--
                    entry.setUnixMode(0100644);
                }
            }
            out.putArchiveEntry(entry);
            try (InputStream in = new BufferedInputStream(new FileInputStream(sourceDir + File.separator + file.getName()))) {
                copy(in, out);
            }
            out.closeArchiveEntry();
        }
    }
}
 
开发者ID:excelsior-oss,项目名称:excelsior-jet-api,代码行数:26,代码来源:Utils.java

示例3: exportFolder

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
@Override
public byte[] exportFolder(Folder folder) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
    zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
    zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
    String xml = createXStream().toXML(folder);
    byte[] xmlBytes = xml.getBytes(StandardCharsets.UTF_8);
    ArchiveEntry zipEntryDesign = newStoredEntry("folder.xml", xmlBytes);
    zipOutputStream.putArchiveEntry(zipEntryDesign);
    zipOutputStream.write(xmlBytes);
    try {
        zipOutputStream.closeArchiveEntry();
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Exception occurred while exporting folder %s.",  folder.getName()));
    }

    zipOutputStream.close();
    return byteArrayOutputStream.toByteArray();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:FoldersServiceBean.java

示例4: exportEntitiesToZIP

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
@Override
public byte[] exportEntitiesToZIP(Collection<? extends Entity> entities) {
    String json = entitySerialization.toJson(entities, null, EntitySerializationOption.COMPACT_REPEATED_ENTITIES);
    byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
    zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
    zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
    ArchiveEntry singleDesignEntry = newStoredEntry("entities.json", jsonBytes);
    try {
        zipOutputStream.putArchiveEntry(singleDesignEntry);
        zipOutputStream.write(jsonBytes);
        zipOutputStream.closeArchiveEntry();
    } catch (Exception e) {
        throw new RuntimeException("Error on creating zip archive during entities export", e);
    } finally {
        IOUtils.closeQuietly(zipOutputStream);
    }
    return byteArrayOutputStream.toByteArray();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:EntityImportExport.java

示例5: compressZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
public static void compressZipFile(
        final File temporaryZipFile,
        final Path pathToCompress,
        final BuildListener listener)
        throws IOException {
    try (final ZipArchiveOutputStream zipArchiveOutputStream =
                 new ZipArchiveOutputStream(
                 new BufferedOutputStream(
                 new FileOutputStream(temporaryZipFile)))) {

        compressArchive(
                pathToCompress,
                zipArchiveOutputStream,
                new ArchiveEntryFactory(CompressionType.Zip),
                CompressionType.Zip,
                listener);
    }
}
 
开发者ID:awslabs,项目名称:aws-codepipeline-plugin-for-jenkins,代码行数:19,代码来源:CompressionTools.java

示例6: canDecompressZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的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.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的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: compress

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
public void compress(File[] files, File zipFile) throws IOException {
	if (files == null) {
		return;
	}
	ZipArchiveOutputStream out = new ZipArchiveOutputStream(zipFile);
	out.setUseZip64(Zip64Mode.AsNeeded);
	// 将每个文件用ZipArchiveEntry封装
	for (File file : files) {
		if (file == null) {
			continue;
		}
		compressOneFile(file, out, "");
	}
	if (out != null) {
		out.close();
	}
}
 
开发者ID:hoozheng,项目名称:AndroidRobot,代码行数:18,代码来源:ZipUtil.java

示例9: createPackageZip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
/**
 * Creates the {@code CRX} package definition.
 *
 * @param packageName Name of the package to create.
 */
public final void createPackageZip(final String packageName) {
    try {
        ArchiveOutputStream archiveOutputStream =
                new ZipArchiveOutputStream(new File("src/main/resources/" + packageName + ".zip"));
        addZipEntry(archiveOutputStream, "META-INF/vault/definition/.content.xml");
        addZipEntry(archiveOutputStream, "META-INF/vault/config.xml");
        addZipEntry(archiveOutputStream, "META-INF/vault/filter.xml");
        addZipEntry(archiveOutputStream, "META-INF/vault/nodetypes.cnd");
        addZipEntry(archiveOutputStream, "META-INF/vault/properties.xml");
        addZipEntry(archiveOutputStream, "jcr_root/.content.xml");
        archiveOutputStream.finish();
        archiveOutputStream.close();
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Unable to create package zip: {0}", e.getMessage());
    }
}
 
开发者ID:steuyfish,项目名称:aem-data-exporter,代码行数:22,代码来源:PackageFileZipper.java

示例10: makeSourceZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
/**
 * Creates a zip file with random content.
 *
 * @author S3460
 * @param source the source
 * @return the zip file
 * @throws Exception the exception
 */
private ZipFile makeSourceZipFile(File source) throws Exception {
  ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(source));
  int size = randomSize(entryMaxSize);
  for (int i = 0; i < size; i++) {
    out.putArchiveEntry(new ZipArchiveEntry("zipentry" + i));
    int anz = randomSize(10);
    for (int j = 0; j < anz; j++) {
      byte[] bytes = getRandomBytes();
      out.write(bytes, 0, bytes.length);
    }
    out.flush();
    out.closeArchiveEntry();
  }
  //add leeres Entry
  out.putArchiveEntry(new ZipArchiveEntry("zipentry" + size));
  out.flush();
  out.closeArchiveEntry();
  out.flush();
  out.finish();
  out.close();
  return new ZipFile(source);
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:31,代码来源:JarDeltaJarPatcherTest.java

示例11: makeTargetZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
/**
 * Writes a modified version of zip_Source into target.
 *
 * @author S3460
 * @param zipSource the zip source
 * @param target the target
 * @return the zip file
 * @throws Exception the exception
 */
private ZipFile makeTargetZipFile(ZipFile zipSource, File target) throws Exception {
  ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(target));
  for (Enumeration<ZipArchiveEntry> enumer = zipSource.getEntries(); enumer.hasMoreElements();) {
    ZipArchiveEntry sourceEntry = enumer.nextElement();
    out.putArchiveEntry(new ZipArchiveEntry(sourceEntry.getName()));
    byte[] oldBytes = toBytes(zipSource, sourceEntry);
    byte[] newBytes = getRandomBytes();
    byte[] mixedBytes = mixBytes(oldBytes, newBytes);
    out.write(mixedBytes, 0, mixedBytes.length);
    out.flush();
    out.closeArchiveEntry();
  }
  out.putArchiveEntry(new ZipArchiveEntry("zipentry" + entryMaxSize + 1));
  byte[] bytes = getRandomBytes();
  out.write(bytes, 0, bytes.length);
  out.flush();
  out.closeArchiveEntry();
  out.putArchiveEntry(new ZipArchiveEntry("zipentry" + (entryMaxSize + 2)));
  out.closeArchiveEntry();
  out.flush();
  out.finish();
  out.close();
  return new ZipFile(targetFile);
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:34,代码来源:JarDeltaJarPatcherTest.java

示例12: runJarPatcher

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
/**
 * Run jar patcher.
 *
 * @param originalName the original name
 * @param targetName the target name
 * @param originalZip the original zip
 * @param newZip the new zip
 * @param comparefiles the comparefiles
 * @throws Exception the exception
 */
private void runJarPatcher(String originalName, String targetName, ZipFile originalZip, ZipFile newZip, boolean comparefiles) throws Exception {
  try (ZipArchiveOutputStream output = new ZipArchiveOutputStream(new FileOutputStream(patchFile))) {
    new JarDelta().computeDelta(originalName, targetName, originalZip, newZip, output);
  }
  ZipFile patch = new ZipFile(patchFile);
  ZipArchiveEntry listEntry = patch.getEntry("META-INF/file.list");
  if (listEntry == null) {
    patch.close();
    throw new IOException("Invalid patch - list entry 'META-INF/file.list' not found");
  }
  BufferedReader patchlist = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
  String next = patchlist.readLine();
  String sourceName = next;
  next = patchlist.readLine();
  new JarPatcher(patchFile.getName(), sourceName).applyDelta(patch, new ZipFile(originalName), new ZipArchiveOutputStream(new FileOutputStream(resultFile)), patchlist);
  if (comparefiles) {
    compareFiles(new ZipFile(targetName), new ZipFile(resultFile));
  }
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:30,代码来源:JarDeltaJarPatcherTest.java

示例13: testJarPatcherIdentFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
/**
 * Tests JarDelta and JarPatcher on two identical files.
 *
 * @throws Exception the exception
 */
@Test
public void testJarPatcherIdentFile() throws Exception {
  ZipFile originalZip = makeSourceZipFile(sourceFile);
  new JarDelta().computeDelta(sourceFile.getAbsolutePath(), sourceFile.getAbsolutePath(), originalZip, originalZip, new ZipArchiveOutputStream(new FileOutputStream(patchFile)));
  ZipFile patch = new ZipFile(patchFile);
  ZipArchiveEntry listEntry = patch.getEntry("META-INF/file.list");
  if (listEntry == null) {
    patch.close();
    throw new IOException("Invalid patch - list entry 'META-INF/file.list' not found");
  }
  BufferedReader patchlist = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
  String next = patchlist.readLine();
  String sourceName = next;
  next = patchlist.readLine();
  ZipFile source = new ZipFile(sourceFile);
  new JarPatcher(patchFile.getName(), sourceName).applyDelta(patch, source, new ZipArchiveOutputStream(new FileOutputStream(resultFile)), patchlist);
  compareFiles(new ZipFile(sourceFile), new ZipFile(resultFile));
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:24,代码来源:JarDeltaJarPatcherTest.java

示例14: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
/**
 * Add one file to the open zip archive stream. Drops the file if it is a directory
 * 
 * @param fileToZip
 * @param baseDir
 * @param os
 * @throws Throwable
 */
public static void zip(File fileToZip, ZipArchiveOutputStream os) throws Throwable {
	if (fileToZip.isDirectory()) return;

	byte buffer[] = new byte[BUFFER_SIZE];
	String name = fileToZip.getName();
	ZipArchiveEntry entry = new ZipArchiveEntry(fileToZip, name);
	entry.setSize(fileToZip.length());
	os.putArchiveEntry(entry);
	BufferedInputStream is = new BufferedInputStream(new FileInputStream(fileToZip), BUFFER_SIZE);
	int count;
	try {
		while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
			os.write(buffer, 0, count);
		}
	} finally {
		is.close();
	}
	os.closeArchiveEntry();
}
 
开发者ID:uom-daris,项目名称:daris,代码行数:28,代码来源:ZipUtil.java

示例15: defaultParameters

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入依赖的package包/类
protected void defaultParameters( String _tag ) throws cfmBadFileException {
	defaultAttribute( "RECURSE", "true" );
	defaultAttribute( "COMPRESSIONLEVEL", ZipArchiveOutputStream.DEFLATED );
	defaultAttribute( "PREFIX", "" );
	defaultAttribute( "OVERWRITE", "true" );
	defaultAttribute( "FLATTEN", "false" );
	defaultAttribute( "CHARSET", System.getProperty( "file.encoding" ) );

	parseTagHeader( _tag );

	if ( containsAttribute( "ATTRIBUTECOLLECTION" ) )
		return;

	if ( !containsAttribute( "ACTION" ) )
		throw newBadFileException( "Missing ACTION", "You need to specify a ACTION - valid actions are CREATE/ZIP, LIST or EXTRACT/UNZIP" );

	if ( !containsAttribute( "ZIPFILE" ) && !containsAttribute( "FILE" ) )
		throw newBadFileException( "Missing ZIPFILE/FILE", "You need to specify a ZIPFILE/FILE" );

}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:21,代码来源:cfZIP.java


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