List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream closeArchiveEntry
public void closeArchiveEntry() throws IOException
From source file:psef.handler.ProjectGetHandler.java
/** * Add files to a tar.gz archive recursively * @param tOut the tar archive output stream * @param path the absolute path to the file/dir to add * @param base the base path inside the tar.gz archive * @throws IOException /*from www .j av a 2 s. c om*/ */ private void addFilesToTarGz(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.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) { addFilesToTarGz(tOut, child.getAbsolutePath(), entryName + "/"); } } } }
From source file:uk.ac.ebi.intact.dataexchange.psimi.exporter.archive.Compressor.java
private void tar(File outputFile, List<File> filesToCompress) throws IOException { OutputStream os = new FileOutputStream(outputFile); TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(os); for (File fileToCompress : filesToCompress) { TarArchiveEntry entry = new TarArchiveEntry(fileToCompress.getName()); entry.setSize(fileToCompress.length()); tarOutput.putArchiveEntry(entry); IOUtils.copy(new FileInputStream(fileToCompress), tarOutput); tarOutput.closeArchiveEntry(); }//from w w w . j ava 2s .co m tarOutput.finish(); tarOutput.close(); os.close(); }
From source file:utybo.branchingstorytree.swing.utils.BSTPackager.java
public static void toPackage(File bstFile, OutputStream out, HashMap<String, String> meta, Consumer<String> cs) throws IOException { TarArchiveOutputStream tar = new TarArchiveOutputStream(new GZIPOutputStream(out)); if (cs != null) { cs.accept("Packaging the main BST file"); }//w w w .j a v a2 s . c o m // Write the main BST file tarFile(bstFile, tar); // Write the resources folder if (cs != null) { cs.accept("Packaging resources"); } tarFolder(new File(bstFile.getParentFile(), "resources"), "resources", tar, cs); // Write the meta file if (cs != null) { cs.accept("Writing meta information"); } meta.put("mainFile", bstFile.getName()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(baos, "UTF-8"); new Gson().toJson(meta, osw); osw.flush(); osw.close(); TarArchiveEntry tae = new TarArchiveEntry("bstmeta.json"); tae.setSize(baos.size()); InputStream bais = baos.toInputStream(); tar.putArchiveEntry(tae); IOUtils.copy(bais, tar); tar.closeArchiveEntry(); tar.close(); if (cs != null) { cs.accept("Done"); } }
From source file:utybo.branchingstorytree.swing.utils.BSTPackager.java
private static void tarFile(File file, String name, TarArchiveOutputStream tar, Consumer<String> cs) throws IOException { if (cs != null) { cs.accept("Packaging " + file.getName()); }// w w w .ja v a2 s . com TarArchiveEntry entry = new TarArchiveEntry(name); entry.setSize(file.length()); tar.putArchiveEntry(entry); FileInputStream fis = new FileInputStream(file); IOUtils.copy(fis, tar); fis.close(); tar.closeArchiveEntry(); }