List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream LONGFILE_GNU
int LONGFILE_GNU
To view the source code for org.apache.commons.compress.archivers.tar TarArchiveOutputStream LONGFILE_GNU.
Click Source Link
From source file:de.uzk.hki.da.pkg.ArchiveBuilder.java
/** * Create an archive file out of the given source folder * /* w w w. j a va 2 s . c o m*/ * @param srcFolder The folder to archive * @param destFile The archive file to build * @param includeFolder Indicates if the source folder will be included to the archive file on * the first level or not * @param compress Indicates if the archive file will be compressed (tgz file) or not (tar file) * @return false if the SIP creation process was aborted during the archive file creation process, otherwise true * @throws Exception */ public boolean archiveFolder(File srcFolder, File destFile, boolean includeFolder, boolean compress) throws Exception { FileOutputStream fOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = null; try { fOut = new FileOutputStream(destFile); if (compress) { gzOut = new GzipCompressorOutputStream(fOut); tOut = new TarArchiveOutputStream(gzOut, "UTF-8"); } else tOut = new TarArchiveOutputStream(fOut, "UTF-8"); tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); tOut.setBigNumberMode(2); if (includeFolder) { if (!addFileToArchive(tOut, srcFolder, "")) return false; } else { File children[] = srcFolder.listFiles(); for (int i = 0; i < children.length; i++) { if (!addFileToArchive(tOut, children[i], "")) return false; } } } finally { tOut.finish(); tOut.close(); if (gzOut != null) gzOut.close(); fOut.close(); } return true; }
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//from ww w .j ava 2 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.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, "."); }//from ww w.j a v a2 s .co m // Close everything up taos.close(); fos.close(); }
From source file:com.github.trask.comet.loadtest.aws.ChefBootstrap.java
private static void addToTarWithBase(File file, TarArchiveOutputStream tarOut, String base) throws IOException { String entryName = base + file.getName(); TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName); tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); tarOut.putArchiveEntry(tarEntry);/*w w w .ja v a2 s. com*/ if (file.isFile()) { IOUtils.copy(new FileInputStream(file), tarOut); tarOut.closeArchiveEntry(); } else { tarOut.closeArchiveEntry(); File[] children = file.listFiles(); if (children != null) { for (File child : children) { addToTarWithBase(child, tarOut, entryName + "/"); } } } }
From source file:ezbake.deployer.cli.commands.SSLCertsCommand.java
@Override public void call() throws IOException, TException { String[] args = globalParameters.unparsedArgs; minExpectedArgs(2, args, this); String securityId = args[0];/* w ww. ja v a 2s . c om*/ String filePath = args[1]; List<ArtifactDataEntry> certs = new ArrayList<>(); EzSecurityRegistration.Client client = null; ThriftClientPool pool = poolSupplier.get(); try { client = pool.getClient(EzSecurityRegistrationConstants.SERVICE_NAME, EzSecurityRegistration.Client.class); AppCerts s = client.getAppCerts( getSecurityToken(pool.getSecurityId(EzSecurityRegistrationConstants.SERVICE_NAME)), securityId); for (AppCerts._Fields fields : AppCerts._Fields.values()) { Object o = s.getFieldValue(fields); if (o instanceof byte[]) { String fieldName = fields.getFieldName().replace("_", "."); TarArchiveEntry tae = new TarArchiveEntry( new File(new File(SSL_CONFIG_DIRECTORY, securityId), fieldName)); certs.add(new ArtifactDataEntry(tae, (byte[]) o)); } } ArchiveStreamFactory asf = new ArchiveStreamFactory(); FileOutputStream fos = new FileOutputStream(filePath); GZIPOutputStream gzs = new GZIPOutputStream(fos); try (TarArchiveOutputStream aos = (TarArchiveOutputStream) asf .createArchiveOutputStream(ArchiveStreamFactory.TAR, gzs)) { aos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (ArtifactDataEntry entry : certs) { aos.putArchiveEntry(entry.getEntry()); IOUtils.write(entry.getData(), aos); aos.closeArchiveEntry(); } aos.finish(); gzs.finish(); } catch (ArchiveException ex) { throw new DeploymentException(ex.getMessage()); } finally { IOUtils.closeQuietly(fos); } } finally { pool.returnToPool(client); } }
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 w ww . j a v a 2 s .co 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:de.uzk.hki.da.pkg.TarGZArchiveBuilder.java
public void archiveFolder(File srcFolder, File destFile, boolean includeFolder) throws Exception { FileOutputStream fOut = null; BufferedOutputStream bOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = null;/*from w w w . j a v a2 s . c o m*/ try { fOut = new FileOutputStream(destFile); bOut = new BufferedOutputStream(fOut); gzOut = new GzipCompressorOutputStream(bOut); tOut = new TarArchiveOutputStream(gzOut); tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); tOut.setBigNumberMode(2); if (includeFolder) addFileToTarGZ(tOut, srcFolder, ""); else { File children[] = srcFolder.listFiles(); for (int i = 0; i < children.length; i++) { addFileToTarGZ(tOut, children[i], ""); } } } finally { tOut.finish(); tOut.close(); gzOut.close(); bOut.close(); fOut.close(); } }
From source file:consulo.cold.runner.execute.target.artifacts.Generator.java
public void buildDistributionInArchive(String distZip, @Nullable String jdkArchivePath, String path, String archiveOutType) throws Exception { myListener.info("Build: " + path); ArchiveStreamFactory factory = new ArchiveStreamFactory(); final File fileZip = new File(myDistPath, distZip); final List<String> executables = Arrays.asList(ourExecutable); try (OutputStream pathStream = createOutputStream(archiveOutType, path)) { ArchiveOutputStream archiveOutputStream = factory.createArchiveOutputStream(archiveOutType, pathStream); if (archiveOutputStream instanceof TarArchiveOutputStream) { ((TarArchiveOutputStream) archiveOutputStream).setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); }// ww w .j av a2s.c o m // move Consulo to archive, and change permissions try (InputStream is = new FileInputStream(fileZip)) { try (ArchiveInputStream ais = factory.createArchiveInputStream(ArchiveStreamFactory.ZIP, is)) { ArchiveEntry tempEntry = ais.getNextEntry(); while (tempEntry != null) { final ArchiveEntryWrapper newEntry = createEntry(archiveOutType, tempEntry.getName(), tempEntry); newEntry.setMode(extractMode(tempEntry)); newEntry.setTime(tempEntry.getLastModifiedDate().getTime()); if (executables.contains(tempEntry.getName())) { newEntry.setMode(0b111_101_101); } copyEntry(archiveOutputStream, ais, tempEntry, newEntry); tempEntry = ais.getNextEntry(); } } } boolean mac = distZip.contains("mac"); // jdk check if (jdkArchivePath != null) { try (InputStream is = new FileInputStream(jdkArchivePath)) { try (GzipCompressorInputStream gz = new GzipCompressorInputStream(is)) { try (ArchiveInputStream ais = factory.createArchiveInputStream(ArchiveStreamFactory.TAR, gz)) { ArchiveEntry tempEntry = ais.getNextEntry(); while (tempEntry != null) { final String name = tempEntry.getName(); // is our path if (!mac && name.startsWith("jre/")) { final ArchiveEntryWrapper jdkEntry = createEntry(archiveOutType, "Consulo/platform/buildSNAPSHOT/" + name, tempEntry); jdkEntry.setMode(extractMode(tempEntry)); jdkEntry.setTime(tempEntry.getLastModifiedDate().getTime()); copyEntry(archiveOutputStream, ais, tempEntry, jdkEntry); } else if (mac && name.startsWith("jdk")) { boolean needAddToArchive = true; for (String prefix : ourMacSkipJdkList) { if (name.startsWith(prefix)) { needAddToArchive = false; } } if (needAddToArchive) { final ArchiveEntryWrapper jdkEntry = createEntry(archiveOutType, "Consulo.app/Contents/platform/buildSNAPSHOT/jre/" + name, tempEntry); jdkEntry.setMode(extractMode(tempEntry)); jdkEntry.setTime(tempEntry.getLastModifiedDate().getTime()); copyEntry(archiveOutputStream, ais, tempEntry, jdkEntry); } } tempEntry = ais.getNextEntry(); } } } } } archiveOutputStream.finish(); } }
From source file:adams.core.io.TarUtils.java
/** * Returns an output stream for the specified tar archive. Automatically * determines the compression used for the archive. Uses GNU long filename * support./* w w w .j a va2s . c o m*/ * * @param input the tar archive to create the output stream for * @param stream the output stream to wrap * @return the output stream * @throws Exception if file not found or similar problems * @see TarArchiveOutputStream#LONGFILE_GNU */ protected static TarArchiveOutputStream openArchiveForWriting(File input, FileOutputStream stream) throws Exception { TarArchiveOutputStream result; Compression comp; comp = determineCompression(input); if (comp == Compression.GZIP) result = new TarArchiveOutputStream(new GzipCompressorOutputStream(new BufferedOutputStream(stream))); else if (comp == Compression.BZIP2) result = new TarArchiveOutputStream(new BZip2CompressorOutputStream(new BufferedOutputStream(stream))); else result = new TarArchiveOutputStream(new BufferedOutputStream(stream)); result.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); return result; }
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 {//from w w w . j av 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); }