List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveEntry setMode
public void setMode(int mode)
From source file:com.pinterest.deployservice.common.TarUtils.java
static void addInputStreamToTar(TarArchiveOutputStream taos, InputStream is, String path, long size, int mode) throws Exception { TarArchiveEntry entry = new TarArchiveEntry(path); entry.setSize(size);/*from w ww . j av a 2s . co m*/ entry.setMode(mode); try { taos.putArchiveEntry(entry); IOUtils.copy(is, taos); } finally { taos.closeArchiveEntry(); Closeables.closeQuietly(is); } }
From source file:com.facebook.buck.artifact_cache.ArtifactUploader.java
/** Archive and compress 'pathsToIncludeInArchive' into 'out', using tar+zstandard. */ @VisibleForTesting//from w w w .j av a 2 s . c o m static void compress(ProjectFilesystem projectFilesystem, Collection<Path> pathsToIncludeInArchive, Path out) throws IOException { try (OutputStream o = new BufferedOutputStream(Files.newOutputStream(out)); OutputStream z = new ZstdCompressorOutputStream(o); TarArchiveOutputStream archive = new TarArchiveOutputStream(z)) { archive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); for (Path path : pathsToIncludeInArchive) { boolean isRegularFile = !projectFilesystem.isDirectory(path); // Add a file entry. TarArchiveEntry e = new TarArchiveEntry(path.toString() + (isRegularFile ? "" : "/")); e.setMode((int) projectFilesystem.getPosixFileMode(path)); e.setModTime(ZipConstants.getFakeTime()); if (isRegularFile) { e.setSize(projectFilesystem.getFileSize(path)); archive.putArchiveEntry(e); try (InputStream input = projectFilesystem.newFileInputStream(path)) { ByteStreams.copy(input, archive); } } else { archive.putArchiveEntry(e); } archive.closeArchiveEntry(); } archive.finish(); } }
From source file:com.fizzed.stork.assembly.AssemblyUtils.java
static public void addFileToTGZStream(TarArchiveOutputStream tgzout, File f, String base, boolean appendName) throws IOException { //File f = new File(path); String entryName = base;/*from w ww . j a va 2 s . c om*/ if (appendName) { if (!entryName.equals("")) { if (!entryName.endsWith("/")) { entryName += "/" + f.getName(); } else { entryName += f.getName(); } } else { entryName += f.getName(); } } TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName); if (f.isFile()) { if (f.canExecute()) { // -rwxr-xr-x tarEntry.setMode(493); } else { // keep default mode } } tgzout.putArchiveEntry(tarEntry); if (f.isFile()) { try (FileInputStream in = new FileInputStream(f)) { IOUtils.copy(in, tgzout); } tgzout.closeArchiveEntry(); } else { tgzout.closeArchiveEntry(); File[] children = f.listFiles(); if (children != null) { for (File child : children) { logger.info(" adding: " + entryName + "/" + child.getName()); addFileToTGZStream(tgzout, child, entryName + "/", true); } } } }
From source file:com.fizzed.stork.util.AssemblyUtils.java
static public void addFileToTGZStream(TarArchiveOutputStream tgzout, File f, String base, boolean appendName) throws IOException { //File f = new File(path); String entryName = base;//from w w w . ja v a 2 s.c o m if (appendName) { if (!entryName.equals("")) { if (!entryName.endsWith("/")) { entryName += "/" + f.getName(); } else { entryName += f.getName(); } } else { entryName += f.getName(); } } TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName); if (f.isFile()) { if (f.canExecute()) { // -rwxr-xr-x tarEntry.setMode(493); } else { // keep default mode } } tgzout.putArchiveEntry(tarEntry); if (f.isFile()) { FileInputStream in = new FileInputStream(f); IOUtils.copy(in, tgzout); in.close(); tgzout.closeArchiveEntry(); } else { tgzout.closeArchiveEntry(); File[] children = f.listFiles(); if (children != null) { for (File child : children) { logger.info(" adding: " + entryName + "/" + child.getName()); addFileToTGZStream(tgzout, child, entryName + "/", true); } } } }
From source file:com.github.wolfposd.jdpkg.deb.DpkgDeb.java
public static void fileEntryToDestination(File source, ArchiveOutputStream archive, boolean atRoot) throws IOException { TarArchiveEntry entry; if (atRoot) { entry = new TarArchiveEntry(source.getName()); } else {//from w ww .j a v a2s. co m entry = new TarArchiveEntry(source.getPath().replace(BuildFile, "")); } entry.setSize(source.length()); entry.setMode(TarArchiveEntry.DEFAULT_FILE_MODE); archive.putArchiveEntry(entry); BufferedInputStream input = new BufferedInputStream(new FileInputStream(source)); IOUtils.copy(input, archive); input.close(); archive.closeArchiveEntry(); }
From source file:lucee.commons.io.compress.CompressUtil.java
private static void compressTar(String parent, Resource source, TarArchiveOutputStream tos, int mode) throws IOException { if (source.isFile()) { //TarEntry entry = (source instanceof FileResource)?new TarEntry((FileResource)source):new TarEntry(parent); TarArchiveEntry entry = new TarArchiveEntry(parent); entry.setName(parent);// w ww . ja v a2s . c o m // mode //100777 TODO ist das so ok? if (mode > 0) entry.setMode(mode); else if ((mode = source.getMode()) > 0) entry.setMode(mode); entry.setSize(source.length()); entry.setModTime(source.lastModified()); tos.putArchiveEntry(entry); try { IOUtil.copy(source, tos, false); } finally { tos.closeArchiveEntry(); } } else if (source.isDirectory()) { compressTar(parent, source.listResources(), tos, mode); } }
From source file:com.gitblit.utils.CompressionUtils.java
/** * Compresses/archives the contents of the tree at the (optionally) * specified revision and the (optionally) specified basepath to the * supplied outputstream./*from www . ja v a 2 s.c o m*/ * * @param algorithm * compression algorithm for tar (optional) * @param repository * @param basePath * if unspecified, entire repository is assumed. * @param objectId * if unspecified, HEAD is assumed. * @param os * @return true if repository was successfully zipped to supplied output * stream */ private static boolean tar(String algorithm, Repository repository, String basePath, String objectId, OutputStream os) { RevCommit commit = JGitUtils.getCommit(repository, objectId); if (commit == null) { return false; } OutputStream cos = os; if (!StringUtils.isEmpty(algorithm)) { try { cos = new CompressorStreamFactory().createCompressorOutputStream(algorithm, os); } catch (CompressorException e1) { error(e1, repository, "{0} failed to open {1} stream", algorithm); } } boolean success = false; 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 { tw.release(); rw.dispose(); } return success; }
From source file:ezbake.deployer.publishers.artifact.ArtifactDataEntryResourceCreator.java
private TarArchiveEntry createTarArchiveEntry(String artifactPath) { TarArchiveEntry archiveEntry = new TarArchiveEntry(new File(artifactPath)); archiveEntry.setMode( archiveEntry.getMode() | Files.convertPosixFilePermissionsToTarArchiveEntryMode(permissions)); return archiveEntry; }
From source file:hudson.util.io.TarArchiver.java
public void visit(File file, String relativePath) throws IOException { if (Functions.isWindows()) relativePath = relativePath.replace('\\', '/'); if (file.isDirectory()) relativePath += '/'; TarArchiveEntry te = new TarArchiveEntry(relativePath); int mode = IOUtils.mode(file); if (mode != -1) te.setMode(mode); te.setModTime(file.lastModified());/* w ww. j ava 2 s . co m*/ if (!file.isDirectory()) te.setSize(file.length()); tar.putArchiveEntry(te); if (!file.isDirectory()) { FileInputStream in = new FileInputStream(file); try { int len; while ((len = in.read(buf)) >= 0) tar.write(buf, 0, len); } finally { in.close(); } } tar.closeArchiveEntry(); entriesWritten++; }
From source file:hudson.util.io.TarArchiver.java
@Override public void visitSymlink(File link, String target, String relativePath) throws IOException { TarArchiveEntry e = new TarArchiveEntry(relativePath, LF_SYMLINK); try {//from w ww. j a va 2 s.co m int mode = IOUtils.mode(link); if (mode != -1) { e.setMode(mode); } } catch (PosixException x) { // ignore } e.setLinkName(target); tar.putArchiveEntry(e); tar.closeArchiveEntry(); entriesWritten++; }