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


Java TarArchiveOutputStream类代码示例

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


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

示例1: addFileToTarGz

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
 * Recursively adds a directory to a .tar.gz. Adapted from http://stackoverflow.com/questions/13461393/compress-directory-to-tar-gz-with-commons-compress
 *
 * @param tOut The .tar.gz to add the directory to
 * @param path The location of the folders and files to add
 * @param base The base path of entry in the .tar.gz
 * @throws IOException Any exceptions thrown during tar creation
 */
private void addFileToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException {
    File f = new File(path);
    String entryName = base + f.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
    tOut.putArchiveEntry(tarEntry);
    Platform.runLater(() -> fileLabel.setText("Processing " + f.getPath()));

    if (f.isFile()) {
        FileInputStream fin = new FileInputStream(f);
        IOUtils.copy(fin, tOut);
        fin.close();
        tOut.closeArchiveEntry();
    } else {
        tOut.closeArchiveEntry();
        File[] children = f.listFiles();
        if (children != null) {
            for (File child : children) {
                addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/");
            }
        }
    }
}
 
开发者ID:wpilibsuite,项目名称:java-installer,代码行数:31,代码来源:TarJREController.java

示例2: tarFolder

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
 * Tar a given folder to a file.
 *
 * @param folder the original folder to tar
 * @param destinationFile the destination file
 * @param waitingHandler a waiting handler used to cancel the process (can
 * be null)
 * @throws FileNotFoundException exception thrown whenever a file is not
 * found
 * @throws ArchiveException exception thrown whenever an error occurred
 * while taring
 * @throws IOException exception thrown whenever an error occurred while
 * reading/writing files
 */
public static void tarFolder(File folder, File destinationFile, WaitingHandler waitingHandler) throws FileNotFoundException, ArchiveException, IOException {
    FileOutputStream fos = new FileOutputStream(destinationFile);
    try {
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        try {
            TarArchiveOutputStream tarOutput = (TarArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.TAR, bos);
            try {
                tarOutput.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
                File matchFolder = folder;
                addFolderContent(tarOutput, matchFolder, waitingHandler);
            } finally {
                tarOutput.close();
            }
        } finally {
            bos.close();
        }
    } finally {
        fos.close();
    }
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:35,代码来源:TarUtils.java

示例3: TarOutputService

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
@CreatesObligation
public TarOutputService(
        final FsModel model,
        final Sink sink,
        final TarDriver driver)
throws IOException {
    Objects.requireNonNull(model);
    this.driver = Objects.requireNonNull(driver);
    final OutputStream out = sink.stream();
    try {
        final TarArchiveOutputStream
                taos = this.taos = new TarArchiveOutputStream(out,
                    DEFAULT_BLKSIZE, DEFAULT_RCDSIZE, driver.getEncoding());
        taos.setAddPaxHeadersForNonAsciiNames(driver.getAddPaxHeaderForNonAsciiNames());
        taos.setLongFileMode(driver.getLongFileMode());
        taos.setBigNumberMode(driver.getBigNumberMode());
    } catch (final Throwable ex) {
        try {
            out.close();
        } catch (final Throwable ex2) {
            ex.addSuppressed(ex2);
        }
        throw ex;
    }
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:26,代码来源:TarOutputService.java

示例4: DebianPackageWriter

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
public DebianPackageWriter ( final OutputStream stream, final GenericControlFile packageControlFile, final TimestampProvider timestampProvider ) throws IOException
{
    this.packageControlFile = packageControlFile;
    this.timestampProvider = timestampProvider;
    if ( getTimestampProvider () == null )
    {
        throw new IllegalArgumentException ( "'timestampProvider' must not be null" );
    }
    BinaryPackageControlFile.validate ( packageControlFile );

    this.ar = new ArArchiveOutputStream ( stream );

    this.ar.putArchiveEntry ( new ArArchiveEntry ( "debian-binary", this.binaryHeader.length, 0, 0, AR_ARCHIVE_DEFAULT_MODE, getTimestampProvider ().getModTime () / 1000 ) );
    this.ar.write ( this.binaryHeader );
    this.ar.closeArchiveEntry ();

    this.dataTemp = File.createTempFile ( "data", null );

    this.dataStream = new TarArchiveOutputStream ( new GZIPOutputStream ( new FileOutputStream ( this.dataTemp ) ) );
    this.dataStream.setLongFileMode ( TarArchiveOutputStream.LONGFILE_GNU );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:DebianPackageWriter.java

示例5: buildAndAddControlFile

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
private void buildAndAddControlFile () throws IOException, FileNotFoundException
{
    final File controlFile = File.createTempFile ( "control", null );
    try
    {
        try ( GZIPOutputStream gout = new GZIPOutputStream ( new FileOutputStream ( controlFile ) );
              TarArchiveOutputStream tout = new TarArchiveOutputStream ( gout ) )
        {
            tout.setLongFileMode ( TarArchiveOutputStream.LONGFILE_GNU );

            addControlContent ( tout, "control", createControlContent (), -1 );
            addControlContent ( tout, "md5sums", createChecksumContent (), -1 );
            addControlContent ( tout, "conffiles", createConfFilesContent (), -1 );
            addControlContent ( tout, "preinst", this.preinstScript, EntryInformation.DEFAULT_FILE_EXEC.getMode () );
            addControlContent ( tout, "prerm", this.prermScript, EntryInformation.DEFAULT_FILE_EXEC.getMode () );
            addControlContent ( tout, "postinst", this.postinstScript, EntryInformation.DEFAULT_FILE_EXEC.getMode () );
            addControlContent ( tout, "postrm", this.postrmScript, EntryInformation.DEFAULT_FILE_EXEC.getMode () );
        }
        addArFile ( controlFile, "control.tar.gz" );
    }
    finally
    {
        controlFile.delete ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:26,代码来源:DebianPackageWriter.java

示例6: addControlContent

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
private void addControlContent ( final TarArchiveOutputStream out, final String name, final ContentProvider content, final int mode ) throws IOException
{
    if ( content == null || !content.hasContent () )
    {
        return;
    }

    final TarArchiveEntry entry = new TarArchiveEntry ( name );
    if ( mode >= 0 )
    {
        entry.setMode ( mode );
    }

    entry.setUserName ( "root" );
    entry.setGroupName ( "root" );
    entry.setSize ( content.getSize () );
    entry.setModTime ( this.getTimestampProvider ().getModTime () );
    out.putArchiveEntry ( entry );
    try ( InputStream stream = content.createInputStream () )
    {
        ByteStreams.copy ( stream, out );
    }
    out.closeArchiveEntry ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:DebianPackageWriter.java

示例7: generateAddProjectTarEntries

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
@SuppressWarnings("PMD.DoNotUseThreads")
private Runnable generateAddProjectTarEntries(Integration integration, OutputStream os) {
    return () -> {
        try (
            TarArchiveOutputStream tos = new TarArchiveOutputStream(os)) {
            tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

            addTarEntry(tos, "src/main/java/io/syndesis/example/Application.java", generate(integration, applicationJavaMustache));
            addTarEntry(tos, "src/main/resources/application.properties", generate(integration, applicationPropertiesMustache));
            addTarEntry(tos, "src/main/resources/syndesis.yml", generateFlow(tos, integration));
            addTarEntry(tos, "pom.xml", generatePom(integration));
            addResource(tos, ".s2i/bin/assemble", "s2i/assemble");
            addExtensions(tos, integration);
            addAdditionalResources(tos);
            LOG.info("Integration [{}]: Project files written to output stream",Names.sanitize(integration.getName()));
        } catch (IOException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(String.format("Exception while creating runtime build tar for integration %s : %s",
                    integration.getName(), e.toString()), e);
            }
        }
    };
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:24,代码来源:DefaultProjectGenerator.java

示例8: addExtensions

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
private void addExtensions(TarArchiveOutputStream tos, Integration integration) throws IOException {
    final Set<String> extensions = collectDependencies(integration).stream()
        .filter(Dependency::isExtension)
        .map(Dependency::getId)
        .collect(Collectors.toCollection(TreeSet::new));

    if (!extensions.isEmpty()) {
        addTarEntry(tos, "src/main/resources/loader.properties", generateExtensionLoader(extensions));

        for (String extensionId : extensions) {
            addTarEntry(
                tos,
                "extensions/" + Names.sanitize(extensionId) + ".jar",
                IOUtils.toByteArray(
                    extensionDataManager.getExtensionBinaryFile(extensionId)
                )
            );
        }
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:21,代码来源:DefaultProjectGenerator.java

示例9: createTarGzipPacker

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
 * create TarGzipPacker object
 */
public static TarGzipPacker createTarGzipPacker(String targetDir, Config config) {
  // this should be received from config
  String archiveFilename = SchedulerContext.jobPackageFileName(config);
  Path archiveFile = Paths.get(targetDir + "/" + archiveFilename);

  try {
    // construct output stream
    OutputStream outStream = Files.newOutputStream(archiveFile);
    GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(outStream);
    TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream);

    return new TarGzipPacker(archiveFile, tarOutputStream);
  } catch (IOException ioe) {
    LOG.log(Level.SEVERE, "Archive file can not be created: " + archiveFile, ioe);
    return null;
  }
}
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:21,代码来源:TarGzipPacker.java

示例10: createTarGZ

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
public static void createTarGZ(String dirPath, String tarGzPath, boolean deleteTempDir) throws IOException {

        try (
                OutputStream fOut  = new FileOutputStream(new File(tarGzPath));
                OutputStream bOut  = new BufferedOutputStream(fOut);
                OutputStream gzOut = new GzipCompressorOutputStream(bOut);
                TarArchiveOutputStream tOut  = new TarArchiveOutputStream(gzOut)
        )
        {
            File f = new File(dirPath);
            if (f.isDirectory()) {
                //pass over all the files in the directory
                File[] children = f.listFiles();
                if (children != null) {
                    for (File child : children) {
                        addFileToTarGz(tOut, child);
                    }
                }
                if(deleteTempDir) {
                    deleteTempFolder(dirPath);
                }
            } else {
                System.out.println("The given directury path is not a directory");
            }
        }
    }
 
开发者ID:CheckPoint-APIs-Team,项目名称:ShowPolicyPackage,代码行数:27,代码来源:TarGZUtils.java

示例11: addFileToTarGz

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
 * This function copies a given file to the zip file
 *
 * @param tarArchiveOutputStream tar output stream of the zip file
 * @param file the file to insert to the zar file
 *
 * @throws IOException
 */
private static void addFileToTarGz(TarArchiveOutputStream tarArchiveOutputStream, File file)
                                        throws IOException
{
    String entryName =  file.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName);
    tarArchiveOutputStream.putArchiveEntry(tarEntry);

    if (file.isFile()) {

        try (FileInputStream input = new FileInputStream(file))
        {
            IOUtils.copy(input, tarArchiveOutputStream);
        }
        tarArchiveOutputStream.closeArchiveEntry();
    } else {//Directory
        System.out.println("The directory which need to be packed to tar folder cannot contain other directories");
    }
}
 
开发者ID:CheckPoint-APIs-Team,项目名称:ShowPolicyPackage,代码行数:27,代码来源:TarGZUtils.java

示例12: initialize

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
@Override
public void initialize(UimaContext aContext)
        throws ResourceInitializationException
{
    super.initialize(aContext);

    // some param check
    if (!outputFile.getName().endsWith(".tar.gz")) {
        throw new ResourceInitializationException(
                new IllegalArgumentException("Output file must have .tar.gz extension"));
    }

    typeSystemWritten = false;

    try {
        outputStream = new TarArchiveOutputStream(new GzipCompressorOutputStream(
                new BufferedOutputStream(new FileOutputStream(outputFile))));
    }
    catch (IOException ex) {
        throw new ResourceInitializationException(ex);
    }
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:23,代码来源:CompressedXmiWriter.java

示例13: archiveDir

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
 * 目录归档
 *
 * @param dir
 * @param taos
 *            TarArchiveOutputStream
 * @param basePath
 * @throws Exception
 */
private static void archiveDir(File dir, TarArchiveOutputStream taos,
                               String basePath) throws Exception {

    File[] files = dir.listFiles();

    if (files.length < 1) {
        TarArchiveEntry entry = new TarArchiveEntry(basePath
                + dir.getName() + PATH);

        taos.putArchiveEntry(entry);
        taos.closeArchiveEntry();
    }

    for (File file : files) {

        // 递归归档
        archive(file, taos, basePath + dir.getName() + PATH);

    }
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:30,代码来源:TarUtils.java

示例14: tar

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
public static void tar(Path inputPath, Path outputPath) throws IOException {
    if (!Files.exists(inputPath)) {
        throw new FileNotFoundException("File not found " + inputPath);
    }

    try (TarArchiveOutputStream tarArchiveOutputStream = buildTarStream(outputPath.toFile())) {
        if (!Files.isDirectory(inputPath)) {
            TarArchiveEntry tarEntry = new TarArchiveEntry(inputPath.toFile().getName());
            if (inputPath.toFile().canExecute()) {
                tarEntry.setMode(tarEntry.getMode() | 0755);
            }
            putTarEntry(tarArchiveOutputStream, tarEntry, inputPath);
        } else {
            Files.walkFileTree(inputPath,
                new TarDirWalker(inputPath, tarArchiveOutputStream));
        }
        tarArchiveOutputStream.flush();
    }
}
 
开发者ID:fabric8io,项目名称:docker-client,代码行数:20,代码来源:ArchiveUtil.java

示例15: generateAddProjectTarEntries

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
private Runnable generateAddProjectTarEntries(GenerateProjectRequest request, OutputStream os) {
    return () -> {
        try (
            TarArchiveOutputStream tos = new TarArchiveOutputStream(os)) {
            tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

            addTarEntry(tos, "src/main/java/io/syndesis/example/Application.java", generateFromRequest(request, applicationJavaMustache));
            addTarEntry(tos, "src/main/resources/application.properties", generateFromRequest(request, applicationPropertiesMustache));
            addTarEntry(tos, "src/main/resources/syndesis.yml", generateFlowYaml(tos, request));
            addTarEntry(tos, "pom.xml", generatePom(request.getIntegration()));

            addAdditionalResources(tos);
            LOG.info("Integration [{}]: Project files written to output stream",Names.sanitize(request.getIntegration().getName()));
        } catch (IOException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(String.format("Exception while creating runtime build tar for integration %s : %s",
                                        request.getIntegration().getName(), e.toString()), e);
            }
        }
    };
}
 
开发者ID:syndesisio,项目名称:syndesis-rest,代码行数:22,代码来源:DefaultProjectGenerator.java


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