List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream close
public void close() throws IOException
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 ww w . 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:jetbrains.exodus.env.EnvironmentTestsBase.java
public static void archiveDB(final String location, final String target) { try {/* w w w .j a va2 s . c o m*/ System.out.println("Dumping " + location + " to " + target); final File root = new File(location); final File targetFile = new File(target); TarArchiveOutputStream tarGz = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(targetFile)), 0x1000)); for (final File file : IOUtil.listFiles(root)) { final long fileSize = file.length(); if (file.isFile() && fileSize != 0) { CompressBackupUtil.archiveFile(tarGz, "", file, fileSize); } } tarGz.close(); } catch (IOException ioe) { System.out.println("Can't create backup"); } }
From source file:com.linkedin.pinot.common.utils.TarGzCompressionUtils.java
/** * Creates a tar.gz file at the specified path with the contents of the * specified directory.// w w w .j ava2 s . c om * * @param directoryPath * The path to the directory to create an archive of * @param tarGzPath * The path to the archive to create * @return tarGzPath * @throws IOException * If anything goes wrong */ public static String createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException { FileOutputStream fOut = null; BufferedOutputStream bOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = null; if (!tarGzPath.endsWith(TAR_GZ_FILE_EXTENTION)) { tarGzPath = tarGzPath + TAR_GZ_FILE_EXTENTION; } 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(); } return tarGzPath; }
From source file:com.shopzilla.hadoop.repl.commands.util.ClusterStateManager.java
public static void compressFiles(Collection<File> files, File output) throws IOException { // Create the output stream for the output file FileOutputStream fos = new FileOutputStream(output); // Wrap the output file stream in streams that will tar and gzip everything TarArchiveOutputStream taos = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(fos))); // 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); // Get to putting all the files in the compressed output file for (File f : files) { addFilesToCompression(taos, f, "."); }/* ww w . ja v a 2 s . co m*/ // Close everything up taos.close(); fos.close(); }
From source file:frameworks.Masken.java
public static void CreateTarGZ(String dirPath, String tarGzPath) { FileOutputStream fOut = null; try {//from w w w .j a va 2s. co m System.out.println(new File(".").getAbsolutePath()); // dirPath = "parent/childDirToCompress/"; // tarGzPath = "archive.tar.gz"; fOut = new FileOutputStream(new File(tarGzPath)); BufferedOutputStream bOut = new BufferedOutputStream(fOut); GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(bOut); TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut); addFileToTarGz(tOut, dirPath, ""); tOut.finish(); tOut.close(); gzOut.close(); bOut.close(); fOut.close(); } catch (FileNotFoundException ex) { Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex); } finally { try { fOut.close(); } catch (IOException ex) { Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.flurry.proguard.UploadMapping.java
/** * Create a gzipped tar archive containing the ProGuard/Native mapping files * * @param files array of mapping.txt files * @return the tar-gzipped archive//from w w w. ja va2s. co m */ private static File createArchive(List<File> files, String uuid) { try { File tarZippedFile = File.createTempFile("tar-zipped-file", ".tgz"); TarArchiveOutputStream taos = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(tarZippedFile)))); for (File file : files) { taos.putArchiveEntry(new TarArchiveEntry(file, (uuid != null && !uuid.isEmpty() ? uuid : UUID.randomUUID()) + ".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:eu.eubrazilcc.lvl.core.io.FileCompressor.java
/** * Creates a tarball from the source directory and writes it into the target directory. * @param srcDir - directory whose files will be added to the tarball * @param targetName - directory where tarball will be written to * @throws IOException when an exception occurs on creating the tarball *//*w ww . j av a2s .c o m*/ public static void tarGzipDir(final String srcDir, final String targetName) throws IOException { FileOutputStream fileOutputStream = null; BufferedOutputStream bufferedOutputStream = null; GzipCompressorOutputStream gzipOutputStream = null; TarArchiveOutputStream tarArchiveOutputStream = null; try { forceMkdir(new File(getFullPath(targetName))); fileOutputStream = new FileOutputStream(new File(targetName)); bufferedOutputStream = new BufferedOutputStream(fileOutputStream); gzipOutputStream = new GzipCompressorOutputStream(bufferedOutputStream); tarArchiveOutputStream = new TarArchiveOutputStream(gzipOutputStream); addFilesInDirectory(tarArchiveOutputStream, srcDir); } finally { if (tarArchiveOutputStream != null) { tarArchiveOutputStream.finish(); } if (tarArchiveOutputStream != null) { tarArchiveOutputStream.close(); } if (gzipOutputStream != null) { gzipOutputStream.close(); } if (bufferedOutputStream != null) { bufferedOutputStream.close(); } if (fileOutputStream != null) { fileOutputStream.close(); } } }
From source file:com.mobilesorcery.sdk.builder.linux.deb.BuilderUtil.java
/** * Adds a directory structure to a gzipped tar. * * @param o The output file that the tar+gz will be written to * @param i The directory to add/* w w w.j ava 2 s .com*/ * * @throws IOException If there's an I/O error */ public void tarGZipDirectory(File o, File i) throws IOException { FileOutputStream fos = new FileOutputStream(o); GzipCompressorOutputStream gzos = new GzipCompressorOutputStream(fos); TarArchiveOutputStream tos = new TarArchiveOutputStream(gzos); // Recursivly add to tar doAddFileToTar(tos, "./", i); // Close tos.close(); gzos.close(); fos.close(); }
From source file:com.puppetlabs.geppetto.forge.v2.api.it.ReleaseTestCreate.java
private byte[] getReleaseImage(ModuleName moduleName, Version version) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); TarArchiveOutputStream tarImage = null; try {//from www.j a v a 2 s .c o m tarImage = new TarArchiveOutputStream(new GZIPOutputStream(bytesOut)); putEntry(tarImage, moduleName, version, "metadata.json", createMetadata(moduleName, version).toString()); putEntry(tarImage, moduleName, version, "manifests/init.pp", createInitPP(moduleName)); } finally { if (tarImage != null) tarImage.close(); } return bytesOut.toByteArray(); }
From source file:com.mulesoft.jockey.maven.GenerateMojo.java
private void createTarGz(File distDir) throws MojoExecutionException { File output = new File(buildDirectory, distributionName + ".tar.gz"); try {// ww w . j a v a 2 s.c o m final OutputStream out = new FileOutputStream(output); TarArchiveOutputStream os = new TarArchiveOutputStream(new GZIPOutputStream(out)); os.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); copyArchiveFile(distDir, os, false); os.finish(); os.close(); out.close(); } catch (IOException e) { throw new MojoExecutionException("Could not create zip file.", e); } projectHelper.attachArtifact(project, "tar.gz", "", output); }