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


Java ArchiveOutputStream类代码示例

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


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

示例1: testApache

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
public void testApache() throws IOException, ArchiveException {
	log.debug("testApache()");
	File zip = File.createTempFile("apache_", ".zip");
	
	// Create zip
	FileOutputStream fos = new FileOutputStream(zip);
	ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
	aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
	aos.closeArchiveEntry();
	aos.close();
	
	// Read zip
	FileInputStream fis = new FileInputStream(zip);
	ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
	ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
	assertEquals(zae.getName(), "coñeta");
	ais.close();
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:19,代码来源:ZipTest.java

示例2: copyArchiveContents

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
/**
 * Copies the contents of an archive file to the specified output stream
 * 
 * @param archiveFile the archive file
 * @param outputStream the output stream
 * @throws IOException error copying the archive contents
 */
private void copyArchiveContents(File archiveFile, ArchiveOutputStream outputStream) throws IOException {
	ArchiveInputStream inputStream = this.createArchiveInputStream(archiveFile);

	ArchiveEntry entry;
	byte[] buffer = new byte[this.bufferSize];

	while ((entry = inputStream.getNextEntry()) != null) {
		outputStream.putArchiveEntry(entry);
		int count;
		while ((count = inputStream.read(buffer)) > 0) {
			outputStream.write(buffer, 0, count);
		}
		outputStream.closeArchiveEntry();
	}
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:23,代码来源:ArchiveFileHandler.java

示例3: addTemplateFiles

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
private void addTemplateFiles(ArchiveOutputStream archive) throws IOException {
  // TODO: maybe get the template path from config?
  Path templateDirectory = FileSystems.getDefault().getPath("tmc-assets", "submission-template");
  List<Path> templateEntries = getDirectoryEntries(templateDirectory);

  for (Path entry : templateEntries) {
    // Paths must be relativized against the template directory root
    // before including them into the Tar archive.
    // I.e. a file at ./tmc-assets/submission-template/directory/file.txt will be added to
    // the archive as ./directory/file.txt.
    String tarEntryName = templateDirectory.relativize(entry).toString();

    // TODO: special case for build.xml for renaming the project.
    addFile(archive, tarEntryName, entry);
  }
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:17,代码来源:SubmissionPackagingService.java

示例4: packageSubmission

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
/**
 * @param additionalFiles A map of filename -> content pairs to include in the package.
 * @return The packaged submission as a TAR archive.
 */
@Override
public byte[] packageSubmission(Map<String, byte[]> additionalFiles)
    throws IOException, ArchiveException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

  try (ArchiveOutputStream archive = new ArchiveStreamFactory()
      .createArchiveOutputStream(ArchiveStreamFactory.TAR, outputStream)) {

    addTemplateFiles(archive);
    addAdditionalFiles(archive, additionalFiles);

    archive.finish();
  }

  logger.debug("Finished packaging submission, size {} bytes.", outputStream.size());

  return outputStream.toByteArray();
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:23,代码来源:SubmissionPackagingService.java

示例5: makeOnlyZip

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
public static void makeOnlyZip() throws IOException, ArchiveException{
	File f1 = new File("D:/compresstest.txt");
       File f2 = new File("D:/test1.xml");
       
       final OutputStream out = new FileOutputStream("D:/中文名字.zip");
       ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out);
       
       os.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
       IOUtils.copy(new FileInputStream(f1), os);
       os.closeArchiveEntry();

       os.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
       IOUtils.copy(new FileInputStream(f2), os);
       os.closeArchiveEntry();
       os.close();
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:17,代码来源:CompressExample.java

示例6: addFilesToZip

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
void addFilesToZip(File source, File destination) throws IOException, ArchiveException {
    OutputStream archiveStream = new FileOutputStream(destination);
    ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
    Collection<File> fileList = FileUtils.listFiles(source, null, true);
    for (File file : fileList) {
        String entryName = getEntryName(source, file);
        ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
        archive.putArchiveEntry(entry);
        BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(input, archive);
        input.close();
        archive.closeArchiveEntry();
    }
    archive.finish();
    archiveStream.close();
}
 
开发者ID:spirylics,项目名称:web2app,代码行数:17,代码来源:Npm.java

示例7: compressDirectory

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
public static void compressDirectory(File rootDir, boolean includeAsRoot, File output) throws IOException {
    if (!rootDir.isDirectory()) {
        throw new IOException("Provided file is not a directory");
    }
    try (OutputStream archiveStream = new FileOutputStream(output);
         ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream)) {
        String rootName = "";
        if (includeAsRoot) {
            insertDirectory(rootDir, rootDir.getName(), archive);
            rootName = rootDir.getName()+"/";
        }
        Collection<File> fileCollection = FileUtils.listFilesAndDirs(rootDir, TrueFileFilter.TRUE, TrueFileFilter.TRUE);
        for (File file : fileCollection) {
            String relativePath = getRelativePath(rootDir, file);
            String entryName = rootName+relativePath;
            if (!relativePath.isEmpty() && !"/".equals(relativePath)) {
                insertObject(file, entryName, archive);
            }
        }
        archive.finish();
    } catch (IOException | ArchiveException e) {
        throw new IOException(e);
    }
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:25,代码来源:ZipUtil.java

示例8: insertFile

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
private static void insertFile(File file, String entryName, ArchiveOutputStream archive) throws IOException {
    if (DEFAULT_EXCLUDES.contains(file.getName())) {
        logger.debug("Skipping ! [l] {}", entryName);
        return;
    }
    if (file.isFile()) {
        ZipArchiveEntry newEntry = new ZipArchiveEntry(entryName);
        setExtraFields(file.toPath(), UnixStat.FILE_FLAG, newEntry);
        archive.putArchiveEntry(newEntry);
        BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(input, archive);
        input.close();
        archive.closeArchiveEntry();
    } else {
        throw new IOException("Provided file is not a file");
    }
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:18,代码来源:ZipUtil.java

示例9: getArchiveInputStream

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
private InputStream getArchiveInputStream(String format, String ...resourceFiles)
        throws ArchiveException, URISyntaxException, IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ArchiveStreamFactory factory = new ArchiveStreamFactory();
    ArchiveOutputStream aout = factory.createArchiveOutputStream(format, bout);

    for (String resource : resourceFiles) {
        File f = new File(getClass().getResource(resource).toURI());
        ArchiveEntry entry = aout.createArchiveEntry(f, resource);
        aout.putArchiveEntry(entry);
        IOUtils.copy(new FileInputStream(f),aout);
        aout.closeArchiveEntry();
    }
    aout.finish();
    aout.close();

    return new ByteArrayInputStream(bout.toByteArray());
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:19,代码来源:TestCommonsCompressDecoderPlugin.java

示例10: compressArchive

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
private static void compressArchive(
        final Path pathToCompress,
        final ArchiveOutputStream archiveOutputStream,
        final ArchiveEntryFactory archiveEntryFactory,
        final CompressionType compressionType,
        final BuildListener listener)
        throws IOException {
    final List<File> files = addFilesToCompress(pathToCompress, listener);

    LoggingHelper.log(listener, "Compressing directory '%s' as a '%s' archive",
            pathToCompress.toString(),
            compressionType.name());

    for (final File file : files) {
        final String newTarFileName = pathToCompress.relativize(file.toPath()).toString();
        final ArchiveEntry archiveEntry = archiveEntryFactory.create(file, newTarFileName);
        archiveOutputStream.putArchiveEntry(archiveEntry);

        try (final FileInputStream fileInputStream = new FileInputStream(file)) {
            IOUtils.copy(fileInputStream, archiveOutputStream);
        }

        archiveOutputStream.closeArchiveEntry();
    }
}
 
开发者ID:awslabs,项目名称:aws-codepipeline-plugin-for-jenkins,代码行数:26,代码来源:CompressionTools.java

示例11: createPackageZip

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

示例12: addZipEntry

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
/**
 * Adds an entry to the zip.
 *
 * @param archiveOutputStream {@code ArchiveOutputStream} to output zip entry to.
 * @param filename Name of the file to add to the zip.
 * @throws IOException If an error occurs adding the file to the zip.
 */
private void addZipEntry(final ArchiveOutputStream archiveOutputStream, final String filename) throws IOException {
    FileInputStream fileInputStream = null;
    try {
        File file = new File("src/main/resources/" + filename);
        ArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(file, filename);
        archiveOutputStream.putArchiveEntry(archiveEntry);
        fileInputStream = new FileInputStream(file);
        IOUtils.copy(fileInputStream, archiveOutputStream);
        archiveOutputStream.closeArchiveEntry();
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Unable to create zip entry for file: [{0}]. {1}",
                new String[]{filename, e.getMessage()});
    } finally {
        if (fileInputStream != null) {
            fileInputStream.close();
        }
    }
}
 
开发者ID:steuyfish,项目名称:aem-data-exporter,代码行数:26,代码来源:PackageFileZipper.java

示例13: compress

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
@Override
public void compress(File[] files, String location, String name)
        throws IOException, ArchiveException, CompressorException {

    initAlgorithmProgress(files);
    String fullname = FileUtils.combinePathAndFilename(location, name);

    try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fullname))) {
        try (CompressorOutputStream cos = makeCompressorOutputStream(bos)) {
            try (ArchiveOutputStream aos = cos != null
                    ? makeArchiveOutputStream(cos)
                    : makeArchiveOutputStream(bos)) {
                compress(files, "", aos);
            }
        }
    }
}
 
开发者ID:turbolocust,项目名称:GZipper,代码行数:18,代码来源:ArchivingAlgorithm.java

示例14: addTargetToArchiveOutputStream

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
/**
     * Add some target to the archive outputstream.
     *
     * @param target              the target to write in the outputstream.
     * @param archiveOutputStream the archive outputstream.
     * @throws IOException if something goes wrong.
     */
    private void addTargetToArchiveOutputStream(Target target, ArchiveOutputStream archiveOutputStream) throws IOException {
        Volume targetVolume = target.getVolume();

        try (InputStream targetInputStream = targetVolume.openInputStream(target)) {
            // get the target infos
            final long targetSize = targetVolume.getSize(target);
            final byte[] targetContent = new byte[(int) targetSize];
            final String targetPath = targetVolume.getPath(target); // relative path

            // creates the entry and writes in the archive output stream
            ArchiveEntry entry = createArchiveEntry(targetPath, targetSize, targetContent);
            archiveOutputStream.putArchiveEntry(entry);
//            archiveOutputStream.write(targetContent);
            IOUtils.copy(targetInputStream, archiveOutputStream);
            archiveOutputStream.closeArchiveEntry();
        }
    }
 
开发者ID:trustsystems,项目名称:elfinder-java-connector,代码行数:25,代码来源:AbstractArchiver.java

示例15: addFilesToZip

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入依赖的package包/类
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
    value = "OBL_UNSATISFIED_OBLIGATION",
    justification = "Lombok construct of @Cleanup is handing this, but not detected by FindBugs")
private static void addFilesToZip(File zipFile, List<File> filesToAdd) throws IOException {
  try {
    @Cleanup
    OutputStream archiveStream = new FileOutputStream(zipFile);
    @Cleanup
    ArchiveOutputStream archive =
        new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);

    for (File fileToAdd : filesToAdd) {
      ZipArchiveEntry entry = new ZipArchiveEntry(fileToAdd.getName());
      archive.putArchiveEntry(entry);

      @Cleanup
      BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToAdd));
      IOUtils.copy(input, archive);
      archive.closeArchiveEntry();
    }

    archive.finish();
  } catch (ArchiveException e) {
    throw new IOException("Issue with creating archive", e);
  }
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:27,代码来源:AzkabanJobHelper.java


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