當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。