List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream putArchiveEntry
public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException
From source file:fr.insalyon.creatis.vip.applicationimporter.server.business.TargzUtils.java
private static void addFileToTarGz(TarArchiveOutputStream tOut, File f, String dir) throws BusinessException { try {//from w w w.j av a2 s.c o m TarArchiveEntry tarEntry; if (dir == null) { tarEntry = new TarArchiveEntry(f, f.getName()); } else { tarEntry = new TarArchiveEntry(f, dir + "/" + f.getName()); } tOut.putArchiveEntry(tarEntry); if (!f.isDirectory()) { FileInputStream in = new FileInputStream(f); IOUtils.copy(in, tOut); tOut.closeArchiveEntry(); in.close(); } else { tOut.closeArchiveEntry(); String name = f.getName(); File[] children = f.listFiles(); if (children != null) { for (File child : children) { addFileToTarGz(tOut, new File(child.getParent() + "/" + child.getName()), name); } } } } catch (IOException ex) { throw new BusinessException(ex); } }
From source file:com.twitter.heron.apiserver.utils.FileHelper.java
private static void addFileToArchive(TarArchiveOutputStream archiveOutputStream, File file, String base) throws IOException { final File absoluteFile = file.getAbsoluteFile(); final String entryName = base + file.getName(); final TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file, entryName); archiveOutputStream.putArchiveEntry(tarArchiveEntry); if (absoluteFile.isFile()) { Files.copy(file.toPath(), archiveOutputStream); archiveOutputStream.closeArchiveEntry(); } else {//w w w. j av a 2 s .c o m archiveOutputStream.closeArchiveEntry(); if (absoluteFile.listFiles() != null) { for (File f : absoluteFile.listFiles()) { addFileToArchive(archiveOutputStream, f, entryName + "/"); } } } }
From source file:com.codenvy.commons.lang.TarUtils.java
private static void addFileEntry(TarArchiveOutputStream tarOut, String entryName, File file, long modTime) throws IOException { final TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName); if (modTime >= 0) { tarEntry.setModTime(modTime);//from w w w.ja v a2 s. com } tarOut.putArchiveEntry(tarEntry); try (InputStream in = new BufferedInputStream(new FileInputStream(file))) { final byte[] buf = new byte[BUF_SIZE]; int r; while ((r = in.read(buf)) != -1) { tarOut.write(buf, 0, r); } } tarOut.closeArchiveEntry(); }
From source file:gobblin.util.io.StreamUtils.java
/** * Helper method for {@link #tar(FileSystem, FileSystem, Path, Path)} that adds a directory entry to a given * {@link TarArchiveOutputStream}./* w ww. j av a 2 s . c o m*/ */ private static void dirToTarArchiveOutputStream(Path destDir, TarArchiveOutputStream tarArchiveOutputStream) throws IOException { TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(formatPathToDir(destDir)); tarArchiveEntry.setModTime(System.currentTimeMillis()); tarArchiveOutputStream.putArchiveEntry(tarArchiveEntry); tarArchiveOutputStream.closeArchiveEntry(); }
From source file:com.codenvy.commons.lang.TarUtils.java
private static void addDirectoryEntry(TarArchiveOutputStream tarOut, String entryName, File directory, long modTime) throws IOException { final TarArchiveEntry tarEntry = new TarArchiveEntry(directory, entryName); if (modTime >= 0) { tarEntry.setModTime(modTime);/* www.ja va 2s. com*/ } tarOut.putArchiveEntry(tarEntry); tarOut.closeArchiveEntry(); }
From source file:gobblin.util.io.StreamUtils.java
/** * Helper method for {@link #tar(FileSystem, FileSystem, Path, Path)} that adds a file entry to a given * {@link TarArchiveOutputStream} and copies the contents of the file to the new entry. *//* w w w . j ava 2s . c om*/ private static void fileToTarArchiveOutputStream(FileStatus fileStatus, FSDataInputStream fsDataInputStream, Path destFile, TarArchiveOutputStream tarArchiveOutputStream) throws IOException { TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(formatPathToFile(destFile)); tarArchiveEntry.setSize(fileStatus.getLen()); tarArchiveEntry.setModTime(System.currentTimeMillis()); tarArchiveOutputStream.putArchiveEntry(tarArchiveEntry); try { IOUtils.copy(fsDataInputStream, tarArchiveOutputStream); } finally { tarArchiveOutputStream.closeArchiveEntry(); } }
From source file:com.flurry.proguard.UploadProGuardMapping.java
/** * Create a gzipped tar archive containing the ProGuard mapping file * * @param file the mapping.txt file/*from w ww . java 2 s .c om*/ * @param uuid the build uuid * @return the tar-gzipped archive */ private static File createArchive(File file, String uuid) { try { File tarZippedFile = File.createTempFile("tar-zipped-file", ".tgz"); TarArchiveOutputStream taos = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(tarZippedFile)))); taos.putArchiveEntry(new TarArchiveEntry(file, uuid + ".txt")); IOUtils.copy(new FileInputStream(file), taos); taos.closeArchiveEntry(); taos.finish(); taos.close(); return tarZippedFile; } catch (IOException e) { failWithError("IO Exception while trying to tar and zip the file.", e); return null; } }
From source file:com.linkedin.pinot.common.utils.TarGzCompressionUtils.java
/** * Creates a tar entry for the path specified with a name built from the base * passed in and the file/directory name. If the path is a directory, a * recursive call is made such that the full directory is added to the tar. * * @param tOut/* www .j av a 2s . c om*/ * The tar file's output stream * @param path * The filesystem path of the file/directory being added * @param base * The base prefix to for the name of the tar file entry * * @throws IOException * If anything goes wrong */ private static void addFileToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException { File f = new File(path); String entryName = base + f.getName(); TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName); tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); tOut.putArchiveEntry(tarEntry); if (f.isFile()) { IOUtils.copy(new FileInputStream(f), tOut); tOut.closeArchiveEntry(); } else { tOut.closeArchiveEntry(); File[] children = f.listFiles(); if (children != null) { for (File child : children) { addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/"); } } } }
From source file:eu.eubrazilcc.lvl.core.io.FileCompressor.java
private static void addFile(final TarArchiveOutputStream tarOutputStream, final String path, final String base) throws IOException { final File file = new File(path); final String entryName = base + file.getName(); final TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName); tarOutputStream.setLongFileMode(LONGFILE_GNU); tarOutputStream.putArchiveEntry(tarEntry); if (file.isFile()) { copy(new FileInputStream(file), tarOutputStream); tarOutputStream.closeArchiveEntry(); } else {/*from www. java 2 s.co m*/ tarOutputStream.closeArchiveEntry(); final File[] children = file.listFiles(); if (children != null) { for (final File child : children) { addFile(tarOutputStream, child.getAbsolutePath(), entryName + separator); } } } }
From source file:com.linkedin.thirdeye.bootstrap.util.TarGzCompressionUtils.java
/** * Creates a tar entry for the path specified with a name built from the base * passed in and the file/directory name. If the path is a directory, a * recursive call is made such that the full directory is added to the tar. * * @param tOut/*www . j a v a 2 s.c o m*/ * The tar file's output stream * @param path * The filesystem path of the file/directory being added * @param base * The base prefix to for the name of the tar file entry * * @throws IOException * If anything goes wrong */ private static void addFileToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException { File f = new File(path); String entryName = base + f.getName(); TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName); FileInputStream fis = null; try { tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); tOut.putArchiveEntry(tarEntry); if (f.isFile()) { fis = new FileInputStream(f); IOUtils.copy(fis, tOut); tOut.closeArchiveEntry(); } else { tOut.closeArchiveEntry(); File[] children = f.listFiles(); if (children != null) { for (File child : children) { addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/"); } } } } finally { if (fis != null) { fis.close(); } } }