List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream TarArchiveOutputStream
public TarArchiveOutputStream(OutputStream os)
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 ww. ja v a 2 s . c o m*/ 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(); }
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 w ww .j a v a 2 s.com*/ taos.close(); }
From source file:edu.jhu.hlt.acute.archivers.tar.TarArchiver.java
/** * Wrap an {@link OutputStream}. */ public TarArchiver(OutputStream os) { this.tos = new TarArchiveOutputStream(os); }
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 . ja v a 2 s. 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:edu.jhu.hlt.concrete.serialization.TarCompactCommunicationSerializer.java
@Override public void toTar(Collection<Communication> commColl, Path outPath) throws ConcreteException, IOException { try (OutputStream os = Files.newOutputStream(outPath); BufferedOutputStream bos = new BufferedOutputStream(os); TarArchiveOutputStream tos = new TarArchiveOutputStream(bos);) { for (Communication c : commColl) { TarArchiveEntry entry = new TarArchiveEntry(c.getId() + ".concrete"); byte[] cbytes = this.toBytes(c); entry.setSize(cbytes.length); tos.putArchiveEntry(entry);//from w w w. j av a2s . c o m try (ByteArrayInputStream bis = new ByteArrayInputStream(cbytes)) { IOUtils.copy(bis, tos); tos.closeArchiveEntry(); } } } catch (IOException e) { throw new ConcreteException(e); } }
From source file:fr.insalyon.creatis.vip.applicationimporter.server.business.TargzUtils.java
public static void createTargz(List<File> pathIn, String pathOut) throws BusinessException { try {/*from w w w . ja va 2 s . c om*/ 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.openshift.client.utils.TarFileTestUtils.java
/** * Replaces the given file(-name), that might exist anywhere nested in the * given archive, by a new entry with the given content. The replacement is * faked by adding a new entry into the archive which will overwrite the * existing (older one) on extraction./*from w w w . ja v a 2 s .c o m*/ * * @param name * the name of the file to replace (no path required) * @param newContent * the content of the replacement file * @param in * @return * @throws IOException * @throws ArchiveException * @throws CompressorException */ public static File fakeReplaceFile(String name, String newContent, InputStream in) throws IOException { Assert.notNull(name); Assert.notNull(in); File newArchive = FileUtils.createRandomTempFile(".tar.gz"); newArchive.deleteOnExit(); TarArchiveOutputStream newArchiveOut = new TarArchiveOutputStream( new GZIPOutputStream(new FileOutputStream(newArchive))); newArchiveOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); TarArchiveInputStream archiveIn = new TarArchiveInputStream(new GZIPInputStream(in)); String pathToReplace = null; try { // copy the existing entries for (ArchiveEntry nextEntry = null; (nextEntry = archiveIn.getNextEntry()) != null;) { if (nextEntry.getName().endsWith(name)) { pathToReplace = nextEntry.getName(); } newArchiveOut.putArchiveEntry(nextEntry); IOUtils.copy(archiveIn, newArchiveOut); newArchiveOut.closeArchiveEntry(); } if (pathToReplace == null) { throw new IllegalStateException("Could not find file " + name + " in the given archive."); } TarArchiveEntry newEntry = new TarArchiveEntry(pathToReplace); newEntry.setSize(newContent.length()); newArchiveOut.putArchiveEntry(newEntry); IOUtils.copy(new ByteArrayInputStream(newContent.getBytes()), newArchiveOut); newArchiveOut.closeArchiveEntry(); return newArchive; } finally { newArchiveOut.finish(); newArchiveOut.flush(); StreamUtils.close(archiveIn); StreamUtils.close(newArchiveOut); } }
From source file:com.fizzed.stork.assembly.AssemblyUtils.java
static public TarArchiveOutputStream createTGZStream(File tgzFile) throws IOException { TarArchiveOutputStream tgzout = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(tgzFile)))); tgzout.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); tgzout.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); return tgzout; }
From source file:edu.jhu.hlt.concrete.serialization.TarGzCompactCommunicationSerializer.java
@Override public void toTarGz(Collection<Communication> commColl, Path outPath) throws ConcreteException { try (OutputStream os = Files.newOutputStream(outPath); BufferedOutputStream bos = new BufferedOutputStream(os); GzipCompressorOutputStream gzos = new GzipCompressorOutputStream(bos); TarArchiveOutputStream tos = new TarArchiveOutputStream(gzos);) { for (Communication c : commColl) { TarArchiveEntry entry = new TarArchiveEntry(c.getId() + ".concrete"); byte[] cbytes = this.toBytes(c); entry.setSize(cbytes.length); tos.putArchiveEntry(entry);/*from www . ja v a 2 s. c o m*/ try (ByteArrayInputStream bis = new ByteArrayInputStream(cbytes)) { IOUtils.copy(bis, tos); tos.closeArchiveEntry(); } } } catch (IOException e) { throw new ConcreteException(e); } }
From source file:mase.me.MEFinalRepertoireStat.java
@Override public void finalStatistics(EvolutionState state, int result) { super.finalStatistics(state, result); if (compress) { try {// w w w . ja va 2s . c o m taos = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(archiveFile)))); } catch (IOException ex) { Logger.getLogger(BestSolutionGenStat.class.getName()).log(Level.SEVERE, null, ex); } } if (!compress && !archiveFile.exists()) { archiveFile.mkdirs(); } MESubpopulation sub = (MESubpopulation) state.population.subpops[0]; Collection<Entry<Integer, Individual>> entries = sub.map.entries(); for (Entry<Integer, Individual> e : entries) { PersistentSolution p = SolutionPersistence.createPersistentController(state, e.getValue(), 0, e.getKey()); p.setUserData(sub.getBehaviourVector(state, e.getValue())); try { if (compress) { SolutionPersistence.writeSolutionToTar(p, taos); } else { SolutionPersistence.writeSolutionInFolder(p, archiveFile); } } catch (IOException ex) { Logger.getLogger(BestSolutionGenStat.class.getName()).log(Level.SEVERE, null, ex); } } if (compress) { try { taos.close(); } catch (IOException ex) { Logger.getLogger(MEFinalRepertoireStat.class.getName()).log(Level.SEVERE, null, ex); } } }