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


Java TarArchiveOutputStream.closeArchiveEntry方法代码示例

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


在下文中一共展示了TarArchiveOutputStream.closeArchiveEntry方法的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: 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

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

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

示例5: addFileToTar

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void addFileToTar(TarArchiveOutputStream tarArchiveOutputStream, String path, String base) {
  File file = new File(path);
  String fileName = file.getName();

  if (Arrays.stream(omitPaths).anyMatch(s -> s.equals(fileName))) {
    return;
  }

  String tarEntryName = String.join("/", base, fileName);
  try {
    if (file.isFile()) {
      TarArchiveEntry tarEntry = new TarArchiveEntry(file, tarEntryName);
      tarArchiveOutputStream.putArchiveEntry(tarEntry);
      IOUtils.copy(new FileInputStream(file), tarArchiveOutputStream);
      tarArchiveOutputStream.closeArchiveEntry();
    } else if (file.isDirectory()) {
      Arrays.stream(file.listFiles())
          .filter(Objects::nonNull)
          .forEach(f -> addFileToTar(tarArchiveOutputStream, f.getAbsolutePath(), tarEntryName));
    } else {
      log.warn("Unknown file type: " + file + " - skipping addition to tar archive");
    }
  } catch (IOException e) {
    throw new HalException(Problem.Severity.FATAL, "Unable to file " + file.getName() + " to archive entry: " + tarEntryName + " " + e.getMessage(), e);
  }
}
 
开发者ID:spinnaker,项目名称:halyard,代码行数:27,代码来源:BackupService.java

示例6: createArchive

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Create a gzipped tar archive containing the ProGuard/Native mapping files
 *
 * @param files array of mapping.txt files
 * @return the tar-gzipped archive
 */
private static File createArchive(List<File> files, String uuid) {
    try {
        File tarZippedFile = File.createTempFile("tar-zipped-file", ".tgz");
        TarArchiveOutputStream taos = new TarArchiveOutputStream(
                    new GZIPOutputStream(
                                new BufferedOutputStream(
                                            new FileOutputStream(tarZippedFile))));
        for (File file : files) {
            taos.putArchiveEntry(new TarArchiveEntry(file,
                    (uuid != null && !uuid.isEmpty() ? uuid : UUID.randomUUID()) + ".txt"));
            IOUtils.copy(new FileInputStream(file), taos);
            taos.closeArchiveEntry();
        }
        taos.finish();
        taos.close();
        return tarZippedFile;
    } catch (IOException e) {
        failWithError("IO Exception while trying to tar and zip the file.", e);
        return null;
    }
}
 
开发者ID:flurry,项目名称:upload-clients,代码行数:28,代码来源:UploadMapping.java

示例7: addFileToArchive

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private static void addFileToArchive(TarArchiveOutputStream archiveOutputStream, File file,
                                     String base) throws IOException {
  final File absoluteFile = file.getAbsoluteFile();
  final String entryName = base + file.getName();
  final TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file, entryName);
  archiveOutputStream.putArchiveEntry(tarArchiveEntry);

  if (absoluteFile.isFile()) {
    Files.copy(file.toPath(), archiveOutputStream);
    archiveOutputStream.closeArchiveEntry();
  } else {
    archiveOutputStream.closeArchiveEntry();
    if (absoluteFile.listFiles() != null) {
      for (File f : absoluteFile.listFiles()) {
        addFileToArchive(archiveOutputStream, f, entryName + "/");
      }
    }
  }
}
 
开发者ID:twitter,项目名称:heron,代码行数:20,代码来源:FileHelper.java

示例8: compressTar

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private static void compressTar(String parent, Resource source,TarArchiveOutputStream tos, int mode) throws IOException {
	if(source.isFile()) {
		//TarEntry entry = (source instanceof FileResource)?new TarEntry((FileResource)source):new TarEntry(parent);
		TarArchiveEntry entry = new TarArchiveEntry(parent);
        
        entry.setName(parent);
        
        // mode
        //100777 TODO ist das so ok?
        if(mode>0)	entry.setMode(mode);
        else if((mode=source.getMode())>0)	entry.setMode(mode);
        
        entry.setSize(source.length());
        entry.setModTime(source.lastModified());
        tos.putArchiveEntry(entry);
        try {
        	IOUtil.copy(source,tos,false);
        } 
        finally {
    		tos.closeArchiveEntry();
        }
    }
    else if(source.isDirectory()) {
        compressTar(parent, source.listResources(),tos,mode);
    }
}
 
开发者ID:lucee,项目名称:Lucee,代码行数:27,代码来源:CompressUtil.java

示例9: addArchive

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void addArchive(File file, TarArchiveOutputStream aos,
		String basepath) throws Exception {
	if (file.exists()) {
		TarArchiveEntry entry = new TarArchiveEntry(basepath + "/"
				+ file.getName());
		entry.setSize(file.length());
		aos.putArchiveEntry(entry);
		BufferedInputStream bis = new BufferedInputStream(
				new FileInputStream(file));
		int count;
		byte data[] = new byte[1024];
		while ((count = bis.read(data, 0, data.length)) != -1) {
			aos.write(data, 0, count);
		}
		bis.close();
		aos.closeArchiveEntry();
	}
}
 
开发者ID:Petasoft,项目名称:Export,代码行数:19,代码来源:ExpProc.java

示例10: addFileToTarGz

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private static 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);

    if (f.isFile()) {
        IOUtils.copy(new FileInputStream(f), tOut);
        tOut.closeArchiveEntry();
    } else {
        tOut.closeArchiveEntry();
        File[] children = f.listFiles();
        if (children != null) {
            for (File child : children) {
                addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/");
            }
        }
    }
}
 
开发者ID:foundation-runtime,项目名称:jenkins-openstack-deployment-plugin,代码行数:20,代码来源:CompressUtils.java

示例11: addArchiveEntry

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void addArchiveEntry(
    TarArchiveOutputStream tarArchiveOutput,
    Object fileContent,
    String pipelineId,
    String fileName
) throws IOException {
  File pipelineFile = File.createTempFile(pipelineId, fileName);
  FileOutputStream pipelineOutputStream = new FileOutputStream(pipelineFile);
  ObjectMapperFactory.get().writeValue(pipelineOutputStream, fileContent);
  pipelineOutputStream.flush();
  pipelineOutputStream.close();
  TarArchiveEntry archiveEntry = new TarArchiveEntry(
      pipelineFile,
      DATA_PIPELINES_FOLDER + pipelineId + "/" + fileName
  );
  archiveEntry.setSize(pipelineFile.length());
  tarArchiveOutput.putArchiveEntry(archiveEntry);
  IOUtils.copy(new FileInputStream(pipelineFile), tarArchiveOutput);
  tarArchiveOutput.closeArchiveEntry();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:21,代码来源:EdgeExecutableStreamingOutput.java

示例12: addFileEntry

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private static void addFileEntry(
    TarArchiveOutputStream tarOut, String entryName, File file, long modTime) throws IOException {
  final TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName);
  if (modTime >= 0) {
    tarEntry.setModTime(modTime);
  }
  tarOut.putArchiveEntry(tarEntry);
  try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
    final byte[] buf = new byte[BUF_SIZE];
    int r;
    while ((r = in.read(buf)) != -1) {
      tarOut.write(buf, 0, r);
    }
  }
  tarOut.closeArchiveEntry();
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:TarUtils.java

示例13: addFileToTarGz

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Creates a tar entry for the path specified with a name built from the base
 * passed in and the file/directory name. If the path is a directory, a
 * recursive call is made such that the full directory is added to the tar.
 * @param tOut
 *          The tar file's output stream
 * @param path
 *          The filesystem path of the file/directory being added
 * @param base
 *          The base prefix to for the name of the tar file entry
 * @throws IOException
 *           If anything goes wrong
 */
private static 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.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
  tOut.putArchiveEntry(tarEntry);

  if (f.isFile()) {
    IOUtils.copy(new FileInputStream(f), tOut);

    tOut.closeArchiveEntry();
  } else {
    tOut.closeArchiveEntry();

    File[] children = f.listFiles();

    if (children != null) {
      for (File child : children) {
        addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/");
      }
    }
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:39,代码来源:TarGzCompressionUtils.java

示例14: compressData

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Compress data
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TarArchiveOutputStream aos = new TarArchiveOutputStream(baos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
                .values()) {
            TarArchiveEntry entry = new TarArchiveEntry(
                    binaryFile.getDesPath());
            entry.setSize(binaryFile.getActualSize());
            aos.putArchiveEntry(entry);
            aos.write(binaryFile.getData());
            aos.closeArchiveEntry();
        }
        aos.flush();
        aos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        aos.close();
        baos.close();
    }
    return baos.toByteArray();
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:33,代码来源:TarProcessor.java

示例15: addDirToArchive

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * adds a directory to a gzip file, recursively
 *
 * @param tos TarArchiveOutputStream
 * @param srcFile File
 */
private void addDirToArchive(TarArchiveOutputStream tos, File srcFile) {
    File[] files = srcFile.listFiles();

    for (File file : files) {
        if (file.isDirectory()) {
            addDirToArchive(tos, file);
            continue;
        }

        try {
            logger.debug("Adding file: " + file.getPath());

            TarArchiveEntry entry = new TarArchiveEntry(file.getPath());
            entry.setName(repository.toURI().relativize(file.toURI()).getPath());
            entry.setSize(file.length());
            tos.putArchiveEntry(entry);
            IOUtils.copy(new FileInputStream(file), tos);
            tos.closeArchiveEntry();

        } catch (IOException ioe) {
            logger.error("can not add to gzip file. " + ioe.getMessage());
        }

    }
}
 
开发者ID:da-wen,项目名称:GitBackup,代码行数:32,代码来源:GzipArchiver.java


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