List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveEntry DEFAULT_FILE_MODE
int DEFAULT_FILE_MODE
To view the source code for org.apache.commons.compress.archivers.tar TarArchiveEntry DEFAULT_FILE_MODE.
Click Source Link
From source file:com.pinterest.deployservice.common.TarUtils.java
/** * Bundle the given map as a list of files, with key as file name and value as content. *//*from w w w.j a v a2s. com*/ public static byte[] tar(Map<String, String> data) throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); TarArchiveOutputStream taos = new TarArchiveOutputStream(new GZIPOutputStream(os)); // TAR originally didn't support long file names, so enable the support for it taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); // Get to putting all the files in the compressed output file for (Map.Entry<String, String> entry : data.entrySet()) { byte[] bytes = entry.getValue().getBytes("UTF8"); InputStream is = new ByteArrayInputStream(bytes); addInputStreamToTar(taos, is, entry.getKey(), bytes.length, TarArchiveEntry.DEFAULT_FILE_MODE); } taos.close(); return os.toByteArray(); }
From source file:com.mobilesorcery.sdk.builder.linux.deb.DebBuilder.java
/** * Adds a new file to package//from ww w . ja v a 2 s . c om * * @param p Path to file */ public void addFile(String p) throws IOException, FileNotFoundException, NoSuchAlgorithmException { File f = new File(p); int m = TarArchiveEntry.DEFAULT_FILE_MODE; if (f.isDirectory() == true) m = TarArchiveEntry.DEFAULT_DIR_MODE; addFile(p, f, m); }
From source file:com.mobilesorcery.sdk.builder.linux.deb.DebBuilder.java
/** * Adds a new file to package/* w ww. j av a 2 s.c om*/ * * @param f The actual file to add * @param p Path to file */ public void addFile(String p, File f) throws IOException, FileNotFoundException, NoSuchAlgorithmException { int m = TarArchiveEntry.DEFAULT_FILE_MODE; if (f.isDirectory() == true) m = TarArchiveEntry.DEFAULT_DIR_MODE; addFile(p, f, m); }
From source file:com.github.wolfposd.jdpkg.deb.DpkgDeb.java
public static void fileEntryToDestination(File source, ArchiveOutputStream archive, boolean atRoot) throws IOException { TarArchiveEntry entry;//from w w w. j a v a 2s . co m if (atRoot) { entry = new TarArchiveEntry(source.getName()); } else { 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:consulo.cold.runner.execute.target.artifacts.Generator.java
private static int extractMode(ArchiveEntry entry) { if (entry instanceof TarArchiveEntry) { return ((TarArchiveEntry) entry).getMode(); }/* w w w .j av a 2 s .com*/ return entry.isDirectory() ? TarArchiveEntry.DEFAULT_DIR_MODE : TarArchiveEntry.DEFAULT_FILE_MODE; }
From source file:io.fabric8.docker.client.impl.BuildImage.java
@Override public OutputHandle fromFolder(String path) { try {//from ww w. j a v a 2s . c o m final Path root = Paths.get(path); final Path dockerIgnore = root.resolve(DOCKER_IGNORE); final List<String> ignorePatterns = new ArrayList<>(); if (dockerIgnore.toFile().exists()) { for (String p : Files.readAllLines(dockerIgnore, UTF_8)) { ignorePatterns.add(path.endsWith(File.separator) ? path + p : path + File.separator + p); } } final DockerIgnorePathMatcher dockerIgnorePathMatcher = new DockerIgnorePathMatcher(ignorePatterns); File tempFile = Files.createTempFile(Paths.get(DEFAULT_TEMP_DIR), DOCKER_PREFIX, BZIP2_SUFFIX).toFile(); try (FileOutputStream fout = new FileOutputStream(tempFile); BufferedOutputStream bout = new BufferedOutputStream(fout); BZip2CompressorOutputStream bzout = new BZip2CompressorOutputStream(bout); final TarArchiveOutputStream tout = new TarArchiveOutputStream(bzout)) { Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dockerIgnorePathMatcher.matches(dir)) { return FileVisitResult.SKIP_SUBTREE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (dockerIgnorePathMatcher.matches(file)) { return FileVisitResult.SKIP_SUBTREE; } final Path relativePath = root.relativize(file); final TarArchiveEntry entry = new TarArchiveEntry(file.toFile()); entry.setName(relativePath.toString()); entry.setMode(TarArchiveEntry.DEFAULT_FILE_MODE); entry.setSize(attrs.size()); tout.putArchiveEntry(entry); Files.copy(file, tout); tout.closeArchiveEntry(); return FileVisitResult.CONTINUE; } }); fout.flush(); } return fromTar(tempFile.getAbsolutePath()); } catch (IOException e) { throw DockerClientException.launderThrowable(e); } }
From source file:org.ngrinder.common.util.CompressionUtils.java
/** * Add a file into tar.//from w ww. j a v a 2 s. c o m * * @param tarStream TarArchive outputStream * @param file file * @param path relative path to append * @throws IOException thrown when having IO problem. */ public static void addFileToTar(TarArchiveOutputStream tarStream, File file, String path) throws IOException { int mode = file.isDirectory() ? TarArchiveEntry.DEFAULT_DIR_MODE : TarArchiveEntry.DEFAULT_FILE_MODE; addFileToTar(tarStream, file, path, mode); }
From source file:org.vafer.jdeb.producers.DataProducerDirectory.java
public void produce(final DataConsumer pReceiver) throws IOException { scanner.scan();//ww w . ja v a 2 s . c om final File baseDir = scanner.getBasedir(); for (String dir : scanner.getIncludedDirectories()) { final File file = new File(baseDir, dir); String dirname = getFilename(baseDir, file); if ("".equals(dirname)) { continue; } if (!isIncluded(dirname)) { continue; } if ('/' != File.separatorChar) { dirname = dirname.replace(File.separatorChar, '/'); } if (!dirname.endsWith("/")) { dirname += "/"; } TarArchiveEntry entry = new TarArchiveEntry(dirname, true); entry.setUserId(0); entry.setUserName("root"); entry.setGroupId(0); entry.setGroupName("root"); entry.setMode(TarArchiveEntry.DEFAULT_DIR_MODE); entry = map(entry); entry.setSize(0); pReceiver.onEachDir(entry.getName(), entry.getLinkName(), entry.getUserName(), entry.getUserId(), entry.getGroupName(), entry.getGroupId(), entry.getMode(), entry.getSize()); } for (String f : scanner.getIncludedFiles()) { final File file = new File(baseDir, f); String filename = getFilename(baseDir, file); if (!isIncluded(filename)) { continue; } if ('/' != File.separatorChar) { filename = filename.replace(File.separatorChar, '/'); } TarArchiveEntry entry = new TarArchiveEntry(filename, true); entry.setUserId(0); entry.setUserName("root"); entry.setGroupId(0); entry.setGroupName("root"); entry.setMode(TarArchiveEntry.DEFAULT_FILE_MODE); entry = map(entry); entry.setSize(file.length()); final InputStream inputStream = new FileInputStream(file); try { pReceiver.onEachFile(inputStream, entry.getName(), entry.getLinkName(), entry.getUserName(), entry.getUserId(), entry.getGroupName(), entry.getGroupId(), entry.getMode(), entry.getSize()); } finally { inputStream.close(); } } }
From source file:org.vafer.jdeb.producers.DataProducerFile.java
public void produce(final DataConsumer pReceiver) throws IOException { String fileName;//www . ja v a 2 s .c om if (destinationName != null && destinationName.trim().length() > 0) { fileName = destinationName.trim(); } else { fileName = file.getName(); } TarArchiveEntry entry = new TarArchiveEntry(fileName, true); entry.setUserId(0); entry.setUserName("root"); entry.setGroupId(0); entry.setGroupName("root"); entry.setMode(TarArchiveEntry.DEFAULT_FILE_MODE); entry = map(entry); entry.setSize(file.length()); final InputStream inputStream = new FileInputStream(file); try { pReceiver.onEachFile(inputStream, entry.getName(), entry.getLinkName(), entry.getUserName(), entry.getUserId(), entry.getGroupName(), entry.getGroupId(), entry.getMode(), entry.getSize()); } finally { inputStream.close(); } }
From source file:org.vafer.jdeb.producers.DataProducerLink.java
@Override public void produce(final DataConsumer pReceiver) throws IOException { TarArchiveEntry entry = new TarArchiveEntry(path, symlink ? TarArchiveEntry.LF_SYMLINK : TarArchiveEntry.LF_LINK); entry.setLinkName(linkName);/*from w ww . ja va 2 s . c o m*/ entry.setUserId(0); entry.setUserName("root"); entry.setGroupId(0); entry.setGroupName("root"); entry.setMode(TarArchiveEntry.DEFAULT_FILE_MODE); entry = map(entry); pReceiver.onEachLink(path, linkName, symlink, entry.getUserName(), entry.getUserId(), entry.getGroupName(), entry.getGroupId(), entry.getMode()); }