Java Code Examples for org.apache.commons.compress.archivers.tar.TarArchiveOutputStream#setLongFileMode()

The following examples show how to use org.apache.commons.compress.archivers.tar.TarArchiveOutputStream#setLongFileMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TarGzCompressionUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * 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 + "/");
      }
    }
  }
}
 
Example 2
Source File: ArchiveUtils.java    From support-diagnostics with Apache License 2.0 6 votes vote down vote up
public static boolean createTarArchive(String dir, String archiveFileName) {

      try {
         File srcDir = new File(dir);
         String filename = dir + "-" + archiveFileName + ".tar.gz";

         FileOutputStream fout = new FileOutputStream(filename);
         CompressorOutputStream cout = new GzipCompressorOutputStream(fout);
         TarArchiveOutputStream taos = new TarArchiveOutputStream(cout);

         taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
         taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
         archiveResultsTar(archiveFileName, taos, srcDir, "", true);
         taos.close();

         logger.info(Constants.CONSOLE,  "Archive: " + filename + " was created");

      } catch (Exception ioe) {
         logger.error( "Couldn't create archive.", ioe);
         return false;
      }

      return true;

   }
 
Example 3
Source File: CompressArchiveUtil.java    From docker-java with Apache License 2.0 6 votes vote down vote up
public static File archiveTARFiles(File base, Iterable<File> files, String archiveNameWithOutExtension) throws IOException {
    File tarFile = new File(FileUtils.getTempDirectoryPath(), archiveNameWithOutExtension + ".tar");
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile));
    try {
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        for (File file : files) {
            TarArchiveEntry tarEntry = new TarArchiveEntry(file);
            tarEntry.setName(relativize(base, file));

            tos.putArchiveEntry(tarEntry);

            if (!file.isDirectory()) {
                FileUtils.copyFile(file, tos);
            }
            tos.closeArchiveEntry();
        }
    } finally {
        tos.close();
    }

    return tarFile;
}
 
Example 4
Source File: Packaging.java    From dekorate with Apache License 2.0 5 votes vote down vote up
public static TarArchiveOutputStream buildTarStream(File outputPath) throws IOException {
  FileOutputStream fout = new FileOutputStream(outputPath);
  BufferedOutputStream bout = new BufferedOutputStream(fout);
  //BZip2CompressorOutputStream bzout = new BZip2CompressorOutputStream(bout);
  TarArchiveOutputStream stream = new TarArchiveOutputStream(bout);
  stream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
  return stream;
}
 
Example 5
Source File: MCRTarServlet.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected TarArchiveOutputStream createContainer(ServletOutputStream sout, String comment) {
    LOGGER.info("Constructing tar archive: {}", comment);
    TarArchiveOutputStream tout = new TarArchiveOutputStream(sout, "UTF8");
    tout.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
    tout.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    return tout;
}
 
Example 6
Source File: CompressedFileReference.java    From vespa with Apache License 2.0 5 votes vote down vote up
public static byte[] compress(File baseDir, List<File> inputFiles) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(out));
    archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    createArchiveFile(archiveOutputStream, baseDir, inputFiles);
    return out.toByteArray();
}
 
Example 7
Source File: FileUtilities.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
/**
 * @param pathElements
 * @param entry
 * @param archiveOutputStream
 * @throws IOException
 */
private static void writeClassPath(LinkedList<String> pathElements, File entry, TarArchiveOutputStream archiveOutputStream) throws IOException {
    if (entry.isFile()) {
        archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        archiveOutputStream.putArchiveEntry(new TarArchiveEntry(entry, getPath(pathElements) + SEPARATOR + entry.getName()));
        copy(entry, archiveOutputStream);
        archiveOutputStream.closeArchiveEntry();
    } else {
        pathElements.addLast(entry.getName());
        for (File child : entry.listFiles()) {
            writeClassPath(pathElements, child, archiveOutputStream);
        }
        pathElements.removeLast();
    }
}
 
Example 8
Source File: TarUtils.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private static TarArchiveOutputStream getTarArchiveOutputStream(String name)
    throws IOException {
  FileOutputStream fileOutputStream = new FileOutputStream(name);
  GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(fileOutputStream);
  TarArchiveOutputStream taos = new TarArchiveOutputStream(gzipOutputStream);

  // TAR has an 8 gig file limit by default, this gets around that
  taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);

  // TAR originally didn't support long file names, so enable the support for it
  taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
  taos.setAddPaxHeadersForNonAsciiNames(true);

  return taos;
}
 
Example 9
Source File: TarBzStripper.java    From reproducible-build-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected TarArchiveOutputStream createOutputStream(File out) throws FileNotFoundException, IOException
{
    final TarArchiveOutputStream stream = new TarArchiveOutputStream(
            new BZip2CompressorOutputStream(new FileOutputStream(out)));
    stream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    return stream;
}
 
Example 10
Source File: TarGzStripper.java    From reproducible-build-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected TarArchiveOutputStream createOutputStream(File out) throws FileNotFoundException, IOException
{
    final TarArchiveOutputStream stream = new TarArchiveOutputStream(
            new GzipCompressorOutputStream(new FileOutputStream(out)));
    stream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    return stream;
}
 
Example 11
Source File: GzipCborFileWriter.java    From ache with Apache License 2.0 5 votes vote down vote up
private void createNewGzipFileStream(File archive) throws IOException {    
    fileOutput = new FileOutputStream(archive);
    bufOutput = new BufferedOutputStream(fileOutput);
    gzipOutput = new GzipCompressorOutputStream(bufOutput);
    tarOutput = new TarArchiveOutputStream(gzipOutput);
    tarOutput.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
}
 
Example 12
Source File: SourceBlobPackager.java    From heroku-maven-plugin with MIT License 5 votes vote down vote up
public static Path pack(SourceBlobDescriptor sourceBlobDescriptor, OutputAdapter outputAdapter) throws IOException {
    Path tarFilePath = Files.createTempFile("heroku-deploy", "source-blob.tgz");

    TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream(
            new GzipCompressorOutputStream(new FileOutputStream(tarFilePath.toFile())));

    tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

    outputAdapter.logInfo("-----> Packaging application...");
    for (Path sourceBlobPath : sourceBlobDescriptor.getContents().keySet()) {
        SourceBlobDescriptor.SourceBlobContent content = sourceBlobDescriptor.getContents().get(sourceBlobPath);

        if (content.isHidden()) {
            outputAdapter.logDebug("       - including: " + sourceBlobPath + " (hidden)");
        } else {
            outputAdapter.logInfo("       - including: " + sourceBlobPath);
        }

        addIncludedPathToArchive(sourceBlobPath.toString(), content, tarArchiveOutputStream);
    }

    tarArchiveOutputStream.close();

    outputAdapter.logInfo("-----> Creating build...");
    outputAdapter.logInfo("       - file: " + tarFilePath);
    outputAdapter.logInfo(String.format("       - size: %dMB", Files.size(tarFilePath) / 1024 / 1024));

    return tarFilePath;
}
 
Example 13
Source File: BuildImageStepExecution.java    From kubernetes-pipeline-plugin with Apache License 2.0 4 votes vote down vote up
DockerImageArchiver(OutputStream out, DockerIgnorePathMatcher dockerIgnore) {
    this.dockerIgnore = dockerIgnore;
    tar = new TarArchiveOutputStream(out);
    tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
}
 
Example 14
Source File: CompressedFileReference.java    From vespa with Apache License 2.0 4 votes vote down vote up
public static File compress(File baseDir, List<File> inputFiles, File outputFile) throws IOException {
    TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(outputFile)));
    archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    createArchiveFile(archiveOutputStream, baseDir, inputFiles);
    return outputFile;
}
 
Example 15
Source File: TarStripper.java    From reproducible-build-maven-plugin with Apache License 2.0 3 votes vote down vote up
/**
 * Factory that create a new instance of tar output stream, for allow extension for different file compression
 * format.
 *
 * @param out the output file.
 * @return a TarArchiveOutputStream for the file.
 * @throws FileNotFoundException
 *             if the file as parameter is not found
 * @throws IOException
 *             if there are error reading the file given as parameter
 *
 */
protected TarArchiveOutputStream createOutputStream(File out) throws FileNotFoundException, IOException
{
    final TarArchiveOutputStream stream = new TarArchiveOutputStream(new FileOutputStream(out));
    stream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    return stream;
}