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

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


          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


            try {
                TarArchiveOutputStream outTarStream =
                    (TarArchiveOutputStream)new ArchiveStreamFactory()
                    .createArchiveOutputStream(ArchiveStreamFactory.TAR, outTarFileStream);
                // Create archive contents
                TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name + ".txt");
                tarArchiveEntry.setSize(fileSize);

                outTarStream.putArchiveEntry(tarArchiveEntry);
                for(long i = 0; i < fileSize; i+= ba_1k.length) {
                    outTarStream.write(ba_1k);
                }
View Full Code Here

  private void untarTarFile(File tarFile, File destDir) throws Exception {
    TarArchiveInputStream tarInputStream = null;
    try {
      tarInputStream = new TarArchiveInputStream(new FileInputStream(tarFile));
      TarArchiveEntry entry = null;
      while ((entry = tarInputStream.getNextTarEntry()) != null) {
        String name = entry.getName();
        LOGGER.debug("Next file: " + name);
        File destFile = new File(destDir, entry.getName());
        if (entry.isDirectory()) {
          destFile.mkdirs();
          continue;
        }
        File destParent = destFile.getParentFile();
        destParent.mkdirs();
View Full Code Here

    if(logMINOR) Logger.minor(this, "Create a TAR Bucket");
   
    TarArchiveOutputStream tarOS = new TarArchiveOutputStream(os);
    try {
      tarOS.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
      TarArchiveEntry ze;

      for (ContainerElement ph : containerItems) {
        if (logMINOR)
          Logger.minor(this, "Putting into tar: " + ph + " data length " + ph.data.size() + " name " + ph.targetInArchive);
        ze = new TarArchiveEntry(ph.targetInArchive);
        ze.setModTime(0);
        long size = ph.data.size();
        ze.setSize(size);
        tarOS.putArchiveEntry(ze);
        BucketTools.copyTo(ph.data, tarOS, size);
        tarOS.closeArchiveEntry();
      }
    } finally {
View Full Code Here

  private void untarTarFile(File tarFile, File destDir) throws Exception {
    TarArchiveInputStream tarInputStream = null;
    try {
      tarInputStream = new TarArchiveInputStream(new FileInputStream(tarFile));
      TarArchiveEntry entry = null;
      while ((entry = tarInputStream.getNextTarEntry()) != null) {
        String name = entry.getName();
        LOGGER.debug("Next file: " + name);
        File destFile = new File(destDir, entry.getName());
        if (entry.isDirectory()) {
          destFile.mkdirs();
          continue;
        }
        File destParent = destFile.getParentFile();
        destParent.mkdirs();
View Full Code Here

   * (you don't want to show your local server paths in the generated files)
   * @throws IOException - in case a file cannot be read
   */
  public static void addFileToTar(final TarArchiveOutputStream stream, final File file, final String name)
      throws IOException {
    TarArchiveEntry tarEntry = new TarArchiveEntry(file, name);
    stream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    stream.putArchiveEntry(tarEntry);
    if (file.isFile()) {
      IOUtils.copy(new FileInputStream(file), stream);
      stream.closeArchiveEntry();
View Full Code Here

                    if (isDir && !name.endsWith("/")) {
                        name += "/";
                    } else if (!isDir && name.endsWith("/")) {
                        name = name.substring(0, name.length() - 1);
                    }
                    TarArchiveEntry ent =
                        new TarArchiveEntry(name, getPreserveLeadingSlashes());
                    ent.setModTime(round(r.getResource().getLastModified(),
                                         1000));
                    ent.setSize(isDir ? 0 : r.getResource().getSize());

                    if (!isDir && r.getCollectionFlags().hasModeBeenSet()) {
                        ent.setMode(r.getCollectionFlags().getMode());
                    } else if (isDir
                               && r.getCollectionFlags().hasDirModeBeenSet()) {
                        ent.setMode(r.getCollectionFlags().getDirMode());
                    } else if (r.getResourceFlags().hasModeBeenSet()) {
                        ent.setMode(r.getResourceFlags().getMode());
                    } else {
                        ent.setMode(isDir
                                    ? ArchiveFileSet.DEFAULT_DIR_MODE
                                    : ArchiveFileSet.DEFAULT_FILE_MODE);
                    }

                    if (r.getResourceFlags().hasUserIdBeenSet()) {
                        ent.setUserId(r.getResourceFlags().getUserId());
                    } else if (r.getCollectionFlags().hasUserIdBeenSet()) {
                        ent.setUserId(r.getCollectionFlags().getUserId());
                    }

                    if (r.getResourceFlags().hasGroupIdBeenSet()) {
                        ent.setGroupId(r.getResourceFlags().getGroupId());
                    } else if (r.getCollectionFlags().hasGroupIdBeenSet()) {
                        ent.setGroupId(r.getCollectionFlags().getGroupId());
                    }
                    if (r.getResourceFlags().hasUserNameBeenSet()) {
                        ent.setUserName(r.getResourceFlags().getUserName());
                    } else if (r.getCollectionFlags().hasUserNameBeenSet()) {
                        ent.setUserName(r.getCollectionFlags().getUserName());
                    }

                    if (r.getResourceFlags().hasGroupNameBeenSet()) {
                        ent.setGroupName(r.getResourceFlags().getGroupName());
                    } else if (r.getCollectionFlags().hasGroupNameBeenSet()) {
                        ent.setGroupName(r.getCollectionFlags().getGroupName());
                    }
                    return ent;
                }
            });
View Full Code Here

    }

    protected void setEntry(ArchiveEntry e) {
        super.setEntry(e);
        if (e != null) {
            TarArchiveEntry te = (TarArchiveEntry) e;
            userName = te.getUserName();
            groupName = te.getGroupName();
        }
    }
View Full Code Here

    final List<File> untaredFiles = new LinkedList<File>();
    final InputStream is = new FileInputStream(inputFile);
    final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory()
        .createArchiveInputStream("tar", is);
    TarArchiveEntry entry = null;
    while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
      final File outputFile = new File(outputDir, entry.getName());
      if (entry.isDirectory()) {
        LOG.info(String.format(
            "Attempting to write output directory %s.", outputFile
                .getAbsolutePath()));
        if (!outputFile.exists()) {
          LOG.info(String.format(
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

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.