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

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


    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


* Time: 9:40 PM
* To change this template use File | Settings | File Templates.
*/
public class TarEntryGenerator {
    public static void generateTarArchiveEntry(TarArchiveOutputStream tOut, byte[] fileContent, String entryName) throws IOException {
         TarArchiveEntry tarEntry = new TarArchiveEntry(entryName);
         tarEntry.setSize(fileContent.length);

         tOut.putArchiveEntry(tarEntry);
         tOut.write(fileContent);
         tOut.closeArchiveEntry();
    }}
View Full Code Here

        if (targetDir.isDirectory()) return;
        if (!input.canRead()) throw new FileNotFoundException("cannot find input "+input);

        System.out.println("unpacking db to "+targetDir);

        TarArchiveEntry entry;
        try (TarArchiveInputStream tis = new TarArchiveInputStream(
                new BZip2CompressorInputStream(
                        new FileInputStream(input))
        )) {
            while ((entry = tis.getNextTarEntry()) != null) {
                File file = new File(targetDir.getParentFile(), entry.getName());
                if (entry.isDirectory()) {
                    if (!file.exists()) assert(file.mkdirs());
                } else if (entry.isFile()) {
                    if (!file.getParentFile().exists()) assert (file.getParentFile().mkdirs());
                    long readBytes = 0;
                    byte[] buffer = new byte[8192];
                    try (FileOutputStream fos = new FileOutputStream(file)) {
                        int n;
                        while (readBytes < entry.getSize()) {
                            n = tis.read(buffer, 0, (int) Math.min(entry.getSize() - readBytes, buffer.length));
                            if (n == -1) {
                                break;
                            }
                            fos.write(buffer, 0, n);
                            readBytes += n;
View Full Code Here

        TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
        tos.setAddPaxHeadersForNonAsciiNames(true);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

        // add the Python script
        TarArchiveEntry pyEntry = new TarArchiveEntry("pt");
        pyEntry.setMode(FileMode.EXECUTABLE_FILE.getBits());
        pyEntry.setModTime(lastModified);
        pyEntry.setSize(pyBytes.length);
        tos.putArchiveEntry(pyEntry);
        tos.write(pyBytes);
        tos.closeArchiveEntry();

        // add a brief readme
        byte [] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt"));
        TarArchiveEntry txtEntry = new TarArchiveEntry("README");
        txtEntry.setMode(FileMode.REGULAR_FILE.getBits());
        txtEntry.setModTime(lastModified);
        txtEntry.setSize(txtBytes.length);
        tos.putArchiveEntry(txtEntry);
        tos.write(txtBytes);
        tos.closeArchiveEntry();

        // cleanup
View Full Code Here

        }
        tw.getObjectId(id, 0);

        ObjectLoader loader = repository.open(id);
        if (FileMode.SYMLINK == mode) {
          TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString(),TarArchiveEntry.LF_SYMLINK);
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          loader.copyTo(bos);
          entry.setLinkName(bos.toString());
          entry.setModTime(modified);
          tos.putArchiveEntry(entry);
          tos.closeArchiveEntry();
        } else {
          TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString());
          entry.setMode(mode.getBits());
          entry.setModTime(modified);
          entry.setSize(loader.getSize());
          tos.putArchiveEntry(entry);
          loader.copyTo(tos);
          tos.closeArchiveEntry();
        }
      }
View Full Code Here

  public void putEntry(ArchiveOutputStream out,
      String path, FileMode mode, ObjectLoader loader)
      throws IOException {
    if (mode == FileMode.SYMLINK) {
      final TarArchiveEntry entry = new TarArchiveEntry(
          path, TarConstants.LF_SYMLINK);
      entry.setLinkName(new String(
          loader.getCachedBytes(100), "UTF-8")); //$NON-NLS-1$
      out.putArchiveEntry(entry);
      out.closeArchiveEntry();
      return;
    }

    // TarArchiveEntry detects directories by checking
    // for '/' at the end of the filename.
    if (path.endsWith("/") && mode != FileMode.TREE) //$NON-NLS-1$
      throw new IllegalArgumentException(MessageFormat.format(
          ArchiveText.get().pathDoesNotMatchMode, path, mode));
    if (!path.endsWith("/") && mode == FileMode.TREE) //$NON-NLS-1$
      path = path + "/"; //$NON-NLS-1$

    final TarArchiveEntry entry = new TarArchiveEntry(path);
    if (mode == FileMode.TREE) {
      out.putArchiveEntry(entry);
      out.closeArchiveEntry();
      return;
    }

    if (mode == FileMode.REGULAR_FILE) {
      // ok
    } else if (mode == FileMode.EXECUTABLE_FILE) {
      entry.setMode(mode.getBits());
    } else {
      // Unsupported mode (e.g., GITLINK).
      throw new IllegalArgumentException(MessageFormat.format(
          ArchiveText.get().unsupportedMode, mode));
    }
    entry.setSize(loader.getSize());
    out.putArchiveEntry(entry);
    loader.copyTo(out);
    out.closeArchiveEntry();
  }
View Full Code Here

      dockerTarFile = new File(tempFolder, "Dockerfile.tar");

      TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream(new FileOutputStream(dockerTarFile));
      tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

      TarArchiveEntry tarEntry = new TarArchiveEntry(dockerfile);
      tarEntry.setName(dockerfile.getName());
      tarArchiveOutputStream.putArchiveEntry(tarEntry);

      FileInputStream fileInputStream = new FileInputStream(dockerfile);
      BufferedInputStream inputStream = new BufferedInputStream(fileInputStream);
      byte[] buffer = new byte[4096];
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

  public void putEntry(ArchiveOutputStream out,
      String path, FileMode mode, ObjectLoader loader)
      throws IOException {
    if (mode == FileMode.SYMLINK) {
      final TarArchiveEntry entry = new TarArchiveEntry(
          path, TarConstants.LF_SYMLINK);
      entry.setLinkName(new String(
          loader.getCachedBytes(100), "UTF-8")); //$NON-NLS-1$
      out.putArchiveEntry(entry);
      out.closeArchiveEntry();
      return;
    }

    final TarArchiveEntry entry = new TarArchiveEntry(path);
    if (mode == FileMode.REGULAR_FILE ||
        mode == FileMode.EXECUTABLE_FILE) {
      entry.setMode(mode.getBits());
    } else {
      // TODO(jrn): Let the caller know the tree contained
      // an entry with unsupported mode (e.g., a submodule).
    }
    entry.setSize(loader.getSize());
    out.putArchiveEntry(entry);
    try {
      loader.copyTo(out);
    } finally {
      out.closeArchiveEntry();
View Full Code Here

       
//      read the zip file and build a query from its contents
        TarArchiveInputStream tis=null;
        try {
          tis = new TarArchiveInputStream( IOUtil.toBufferedInputStream(tarFile.getInputStream()) ) ;    
          TarArchiveEntry entry;
          int mode;
          while ( ( entry = tis.getNextTarEntry()) != null ) {
            //print.ln(entry);
            Resource target=targetDir.getRealResource(entry.getName());
              if(entry.isDirectory()) {
                  target.mkdirs();
              }
              else {
                Resource parent=target.getParentResource();
                  if(!parent.exists())parent.mkdirs();
                  IOUtil.copy(tis,target,false);
              }
              target.setLastModified(entry.getModTime().getTime());
              mode=entry.getMode();
              if(mode>0)target.setMode(mode);
              //tis.closeEntry() ;
          }
        }
        finally {
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.