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

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


    byte[] bytes = new byte[len];
    r.nextBytes(bytes);

    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();

    LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
    ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
        + ".tar.gz")));
    ret.setSize(len);
View Full Code Here


        // unix: download a tar.gz file with pt.py set with execute permissions
        response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\"");

        OutputStream os = response.getOutputStream();
        CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, os);
        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
        tos.finish();
        tos.close();
        cos.close();
        os.flush();
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

    RevWalk rw = new RevWalk(repository);
    TreeWalk tw = new TreeWalk(repository);
    try {
      tw.reset();
      tw.addTree(commit.getTree());
      TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
      tos.setAddPaxHeadersForNonAsciiNames(true);
      tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
      if (!StringUtils.isEmpty(basePath)) {
        PathFilter f = PathFilter.create(basePath);
        tw.setFilter(f);
      }
      tw.setRecursive(true);
      MutableObjectId id = new MutableObjectId();
      long modified = commit.getAuthorIdent().getWhen().getTime();
      while (tw.next()) {
        FileMode mode = tw.getFileMode(0);
        if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
          continue;
        }
        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();
        }
      }
      tos.finish();
      tos.close();
      cos.close();
      success = true;
    } catch (IOException e) {
      error(e, repository, "{0} failed to {1} stream files from commit {2}", algorithm, commit.getName());
    } finally {
View Full Code Here

public final class TarFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
  private static final List<String> SUFFIXES = Collections
      .unmodifiableList(Arrays.asList(".tar")); //$NON-NLS-1$

  public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
    TarArchiveOutputStream out = new TarArchiveOutputStream(s, "UTF-8"); //$NON-NLS-1$
    out.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    out.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
    return out;
  }
View Full Code Here

      outputStreamWriter.close();
      fileOutputStream.close();

      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];
      int bytes_read;
      while ((bytes_read = inputStream.read(buffer)) != -1) {
        tarArchiveOutputStream.write(buffer, 0, bytes_read);
      }
      inputStream.close();

      tarArchiveOutputStream.closeArchiveEntry();
      tarArchiveOutputStream.close();
     
      if (logger.isDebugEnabled()) {
        logger.debug("Dockerfile: Created a docker tar file at " + dockerTarFile.toString());
      }
      return dockerTarFile;
View Full Code Here

    public Tar() {
        setFactory(new TarStreamFactory(){
                public ArchiveOutputStream getArchiveStream(OutputStream stream,
                                                            String encoding)
                    throws IOException {
                    TarArchiveOutputStream o =
                        (TarArchiveOutputStream) super.getArchiveStream(stream,
                                                                        encoding);
                    if (format.equals(Format.OLDGNU)) {
                        o.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
                    }
                    return o;
                }
            });
        setEntryBuilder(
View Full Code Here

public class TarFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
  private static final List<String> SUFFIXES =
      Collections.unmodifiableList(Arrays.asList(".tar"));

  public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
    TarArchiveOutputStream out = new TarArchiveOutputStream(s, "UTF-8"); //$NON-NLS-1$
    out.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    out.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
    return out;
  }
View Full Code Here

    public static void compressTar(Resource[] sources,OutputStream target, int mode) throws IOException {
        if(target instanceof TarArchiveOutputStream){
            compressTar("",sources,(TarArchiveOutputStream)target,mode);
            return;
        }
        TarArchiveOutputStream tos=new TarArchiveOutputStream(target);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        try {
            compressTar("",sources, tos,mode);
        }
        finally {
        IOUtil.closeEL(tos);
View Full Code Here

        tmp.delete();
        running=false;
      }
    }
    private void runTar(Resource res) {
      TarArchiveOutputStream tos=null;
      try {
        tos=new TarArchiveOutputStream(res.getOutputStream());
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
            // wait for sync   
        while(true) {
          sleepEL();
          if(zip.syn+interval<=System.currentTimeMillis()) break;
        }
View Full Code Here

        return monitorPackage;
      }
      FileUtils.deleteQuietly(monitorPackage);
      final String basePath = "ngrinder-monitor/";
      final String libPath = basePath + "lib/";
      TarArchiveOutputStream tarOutputStream = null;
      try {
        tarOutputStream = createTarArchiveStream(monitorPackage);
        addFolderToTar(tarOutputStream, basePath);
        addFolderToTar(tarOutputStream, libPath);
        final URLClassLoader classLoader = (URLClassLoader) getClass().getClassLoader();
View Full Code Here

TOP

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

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.