List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream close
public void close() throws IOException
From source file:jetbrains.exodus.util.CompressBackupUtil.java
private static void cleanUp(TarArchiveOutputStream tarOut, File dest) { if (tarOut != null) { try {//from w w w .ja v a 2 s . c o m tarOut.close(); } catch (IOException e) { // nothing to do here } } IOUtil.deleteFile(dest); }
From source file:fr.insalyon.creatis.vip.applicationimporter.server.business.TargzUtils.java
public static void createTargz(List<File> pathIn, String pathOut) throws BusinessException { try {/* w w w . ja va 2s .c o m*/ FileOutputStream fos = new FileOutputStream(pathOut); TarArchiveOutputStream tos = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(fos))); for (File entry : pathIn) { addFileToTarGz(tos, entry, null); } tos.finish(); tos.close(); } catch (IOException ex) { throw new BusinessException(ex); } }
From source file:com.fizzed.stork.util.AssemblyUtils.java
/** * Create .tar.gz archive file "name.tar.gz" with the contents of inputDir * using the prefix of "/name"// w ww. ja v a 2 s . c om * @param outputDir * @param inputDir * @param name * @return * @throws IOException */ static public File createTGZ(File outputDir, File inputDir, String name) throws IOException { // create tarball File tgzFile = new File(outputDir, name + ".tar.gz"); TarArchiveOutputStream tgzout = null; try { tgzout = AssemblyUtils.createTGZStream(tgzFile); addFileToTGZStream(tgzout, inputDir, name, false); } finally { if (tgzout != null) { tgzout.close(); } } return tgzFile; }
From source file:msec.org.TarUtil.java
public static void archive(File srcFile, File destFile) throws Exception { TarArchiveOutputStream taos = new TarArchiveOutputStream(new FileOutputStream(destFile)); taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); archive(srcFile, taos, ""); taos.flush();/*from www . ja v a 2s . c om*/ taos.close(); }
From source file:jetbrains.exodus.util.CompressBackupUtil.java
/** * Compresses the content of source and stores newly created archive in dest. * In case source is a directory, it will be compressed recursively. * * @param source file or folder to be archived. Should exist on method call. * @param dest path to the archive to be created. Should not exist on method call. * @throws IOException in case of any issues with underlying store. * @throws FileNotFoundException in case source does not exist. *//*from www . ja va2 s.c o m*/ public static void tar(@NotNull File source, @NotNull File dest) throws IOException { if (!source.exists()) { throw new IllegalArgumentException("No source file or folder exists: " + source.getAbsolutePath()); } if (dest.exists()) { throw new IllegalArgumentException( "Destination refers to existing file or folder: " + dest.getAbsolutePath()); } TarArchiveOutputStream tarOut = null; try { tarOut = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(dest)), 0x1000)); doTar("", source, tarOut); tarOut.close(); } catch (IOException e) { cleanUp(tarOut, dest); // operation filed, let's remove the destination archive throw e; } }
From source file:com.ipcglobal.fredimport.util.FredUtils.java
/** * Creates a tar.gz file at the specified path with the contents of the specified directory. * * @param directoryPath the directory path * @param tarGzPath the tar gz path/* w ww.j ava 2s . c o m*/ * @throws IOException If anything goes wrong */ public static void createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException { FileOutputStream fOut = null; BufferedOutputStream bOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = null; try { fOut = new FileOutputStream(new File(tarGzPath)); bOut = new BufferedOutputStream(fOut); gzOut = new GzipCompressorOutputStream(bOut); tOut = new TarArchiveOutputStream(gzOut); addFileToTarGz(tOut, directoryPath, "/"); } finally { tOut.finish(); tOut.close(); gzOut.close(); bOut.close(); fOut.close(); } }
From source file:com.github.trask.comet.loadtest.aws.ChefBootstrap.java
private static void prepareCookbook(String cookbooksDir, List<String> cookbooks, String destFilename) throws IOException, FileNotFoundException { TarArchiveOutputStream cookbooksTarOut = new TarArchiveOutputStream( new GZIPOutputStream(new FileOutputStream(destFilename))); for (String cookbook : cookbooks) { File cookbookDir = new File(cookbooksDir, cookbook); if (!cookbookDir.exists()) { throw new IllegalStateException("missing cookbook " + cookbookDir); }//w w w.ja v a2 s . c o m addToTarWithBase(cookbookDir, cookbooksTarOut, "cookbooks/"); } cookbooksTarOut.close(); }
From source file:com.linkedin.thirdeye.bootstrap.util.TarGzCompressionUtils.java
/** * Creates a tar.gz file at the specified path with the contents of the * specified directory./* ww w . j a v a2s . c om*/ * * @param dirPath * The path to the directory to create an archive of * @param archivePath * The path to the archive to create * * @throws IOException * If anything goes wrong */ public static void createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException { FileOutputStream fOut = null; BufferedOutputStream bOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = null; try { fOut = new FileOutputStream(new File(tarGzPath)); bOut = new BufferedOutputStream(fOut); gzOut = new GzipCompressorOutputStream(bOut); tOut = new TarArchiveOutputStream(gzOut); tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); addFileToTarGz(tOut, directoryPath, ""); } finally { tOut.finish(); tOut.close(); gzOut.close(); bOut.close(); fOut.close(); } }
From source file:com.ttech.cordovabuild.infrastructure.archive.ArchiveUtils.java
public static void compressDirectory(Path path, OutputStream output) { try {//from ww w . j av a2 s . com // Wrap the output file stream in streams that will tar and gzip everything TarArchiveOutputStream taos = new TarArchiveOutputStream(new GZIPOutputStream(output)); // TAR has an 8 gig file limit by default, this gets around that taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); // to get past the 8 gig limit // TAR originally didn't support long file names, so enable the support for it taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (File child : path.toFile().listFiles()) { addFileToTarGz(taos, child.toPath(), ""); } taos.close(); } catch (IOException e) { throw new ApplicationSourceException(e); } }
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. ja 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(); }