Package org.apache.commons.compress.archivers.tar

Examples of org.apache.commons.compress.archivers.tar.TarArchiveEntry


        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);
View Full Code Here


                Files.createDirectories(destDir);
            }

            TarArchiveInputStream in = new TarArchiveInputStream(new GzipCompressorInputStream(Files.newInputStream(tgzFile)));

            TarArchiveEntry entry;
            while ((entry = in.getNextTarEntry()) != null) {
                if (entry.isDirectory()) {
                    Path dir = destDir.resolve(entry.getName());
                    logger.trace("Create dir {}", dir);
                    Files.createDirectories(dir);
                } else {
                    Path file = destDir.resolve(entry.getName());
                    logger.trace("Create file {}: {} bytes", file, entry.getSize());
                    OutputStream out = Files.newOutputStream(file);
                    IOUtils.copy(in, out);
                    out.close();
                }
            }
View Full Code Here

                Files.createDirectories(destDir);
            }

            TarArchiveInputStream in = new TarArchiveInputStream(new GzipCompressorInputStream(Files.newInputStream(tgzFile)));

            TarArchiveEntry entry;
            while ((entry = in.getNextTarEntry()) != null) {
                if (entry.isDirectory()) {
                    Path dir = destDir.resolve(entry.getName());
                    logger.trace("Create dir {}", dir);
                    Files.createDirectories(dir);
                } else {
                    Path file = destDir.resolve(entry.getName());
                    logger.trace("Create file {}: {} bytes", file, entry.getSize());
                    OutputStream out = Files.newOutputStream(file);
                    IOUtils.copy(in, out);
                    out.close();
                }
            }
View Full Code Here

            }

            // Add any that haven't yet been processed (from shortest to longest)
            for (int pathIndex = longestSeenBefore - 1; pathIndex >= 0; pathIndex--) {
                final String pathName = paths.get(pathIndex);
                TarArchiveEntry entry = new TarArchiveEntry(pathName);
                String dirName = FilenameUtils.getName(pathName.substring(0, pathName.length() - 1));
                longestParentId = submitDirectory(parentName, entry, dirName, longestParentId);
                directories.put(pathName, longestParentId);
            }
           
View Full Code Here

    public void setup() throws Exception {
       
        fileName = getClass().getResource("/saved.tar").getFile();
       
        in = new TarArchiveInputStream(new FileInputStream(fileName));
        TarArchiveEntry entry;
        while ((entry = in.getNextTarEntry()) != null) {
            entryName = entry.getName();
            if ("saved/profile.xml".equals(entryName)) {
                size = entry.getSize();
                modTime = entry.getModTime();
                metaData = new RequestMetaData(modTime.getTime(), size, "profile.xml");
                identifier = new RequestIdentifier(ArchiveFileUtils.toTarUri(new File(fileName).toURI(), entryName));
                break;
            }
        }
View Full Code Here

      }

      if (pathToReplace == null) {
        throw new IllegalStateException("Could not find file " + name + " in the given archive.");
      }
      TarArchiveEntry newEntry = new TarArchiveEntry(pathToReplace);
      newEntry.setSize(newContent.length());
      newArchiveOut.putArchiveEntry(newEntry);
      IOUtils.copy(new ByteArrayInputStream(newContent.getBytes()), newArchiveOut);
      newArchiveOut.closeArchiveEntry();

      return newArchive;
View Full Code Here

                Files.createDirectories(destDir);
            }

            TarArchiveInputStream in = new TarArchiveInputStream(new GzipCompressorInputStream(Files.newInputStream(tgzFile)));

            TarArchiveEntry entry;
            while ((entry = in.getNextTarEntry()) != null) {
                if (entry.isDirectory()) {
                    Path dir = destDir.resolve(entry.getName());
                    logger.trace("Create dir {}", dir);
                    Files.createDirectories(dir);
                } else {
                    Path file = destDir.resolve(entry.getName());
                    logger.trace("Create file {}: {} bytes", file, entry.getSize());
                    OutputStream out = Files.newOutputStream(file);
                    IOUtils.copy(in, out);
                    out.close();
                }
            }
View Full Code Here

          OutputStream outputStream = new FileOutputStream( new File( archive) );         
          ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("tar", outputStream);
         
      if (files != null) {
        for (File file: files) {
              final TarArchiveEntry entry = new TarArchiveEntry("testdata/test1.xml");
              entry.setModTime(0);
              entry.setSize(file.length());
              entry.setUserId(0);
              entry.setGroupId(0);
              entry.setMode(0100000);
              os.putArchiveEntry(entry);
              IOUtils.copy(new FileInputStream(file), os);
        }
      }
          os.closeArchiveEntry();
View Full Code Here

    File archiveFile = new File(p.toUri().getPath() + ".tar");
    archiveFile.createNewFile();
    TarArchiveOutputStream out = new TarArchiveOutputStream(
        new FileOutputStream(archiveFile));
    TarArchiveEntry entry = new TarArchiveEntry(p.getName());
    entry.setSize(bytes.length);
    out.putArchiveEntry(entry);
    out.write(bytes);
    out.closeArchiveEntry();
    out.close();
View Full Code Here

    File gzipFile = new File(p.toUri().getPath() + ".tar.gz");
    gzipFile.createNewFile();
    TarArchiveOutputStream out = new TarArchiveOutputStream(
        new GZIPOutputStream(new FileOutputStream(gzipFile)));
    TarArchiveEntry entry = new TarArchiveEntry(p.getName());
    entry.setSize(bytes.length);
    out.putArchiveEntry(entry);
    out.write(bytes);
    out.closeArchiveEntry();
    out.close();
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.tar.TarArchiveEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.