List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream closeArchiveEntry
public void closeArchiveEntry() throws IOException
From source file:com.vmware.admiral.closures.util.ClosureUtils.java
private static void putTarEntry(TarArchiveOutputStream tarOutputStream, TarArchiveEntry tarEntry, InputStream inStream, long size) throws IOException { tarEntry.setSize(size);//ww w . j a va2 s . co m tarOutputStream.putArchiveEntry(tarEntry); try (InputStream input = new BufferedInputStream(inStream)) { long byteRead = copy(input, tarOutputStream); logInfo("---- BYTES READ %s ", byteRead); tarOutputStream.closeArchiveEntry(); } }
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 {// w w w . j a va2 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.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/*from ww w. j av 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); 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:com.flurry.proguard.UploadProGuardMapping.java
/** * Create a gzipped tar archive containing the ProGuard mapping file * * @param file the mapping.txt file/*from www . jav a 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:msec.org.TarUtil.java
private static void archiveFile(File file, TarArchiveOutputStream taos, String dir) throws Exception { TarArchiveEntry entry = new TarArchiveEntry(dir + file.getName()); entry.setSize(file.length());// w w w. jav a 2 s .c o m taos.putArchiveEntry(entry); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); int count; byte data[] = new byte[BUFFERSZ]; while ((count = bis.read(data, 0, BUFFERSZ)) != -1) { taos.write(data, 0, count); } bis.close(); taos.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. *///from w ww. j a v a2 s . co m 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:ezbake.protect.ezca.EzCABootstrap.java
protected static void addTarArchiveEntry(final TarArchiveOutputStream tao, String name, byte[] data) { TarArchiveEntry tae = new TarArchiveEntry(name); try {//from www . j av a 2 s .c o m tae.setSize(data.length); tao.putArchiveEntry(tae); tao.write(data); tao.closeArchiveEntry(); } catch (IOException e) { e.printStackTrace(); } }
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 w w w . j a v a2 s . c om 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/*w w w . j av a2 s .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); 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(); } } }
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);/* ww w. j av a2 s. c o m*/ } 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(); }