List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream finish
public void finish() throws IOException
From source file:org.waarp.common.tar.TarUtility.java
/** * Create a new Tar from a root directory * /*ww w . jav a2 s . c o m*/ * @param directory * the base directory * @param filename * the output filename * @param absolute * store absolute filepath (from directory) or only filename * @return True if OK */ public static boolean createTarFromDirectory(String directory, String filename, boolean absolute) { File rootDir = new File(directory); File saveFile = new File(filename); // recursive call TarArchiveOutputStream taos; try { taos = new TarArchiveOutputStream(new FileOutputStream(saveFile)); } catch (FileNotFoundException e) { return false; } taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); try { recurseFiles(rootDir, rootDir, taos, absolute); } catch (IOException e2) { try { taos.close(); } catch (IOException e) { // ignore } return false; } try { taos.finish(); } catch (IOException e1) { // ignore } try { taos.flush(); } catch (IOException e) { // ignore } try { taos.close(); } catch (IOException e) { // ignore } return true; }
From source file:org.waarp.common.tar.TarUtility.java
/** * Create a new Tar from an array of Files (only name of files will be used) * //from ww w .j a v a 2 s . c om * @param files * array of files to add * @param filename * the output filename * @return True if OK */ public static boolean createTarFromFiles(File[] files, String filename) { File saveFile = new File(filename); // recursive call TarArchiveOutputStream taos; try { taos = new TarArchiveOutputStream(new FileOutputStream(saveFile)); } catch (FileNotFoundException e) { return false; } taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (File file : files) { try { addFile(file, taos); } catch (IOException e) { try { taos.close(); } catch (IOException e1) { // ignore } return false; } } try { taos.finish(); } catch (IOException e1) { // ignore } try { taos.flush(); } catch (IOException e) { // ignore } try { taos.close(); } catch (IOException e) { // ignore } return true; }
From source file:psef.handler.ProjectGetHandler.java
/** * Convert the root into a tarball//from ww w . j a v a2 s.c om * @return file pointing to the temporary tar.gz file */ private File tarRoot() throws IOException { TarArchiveOutputStream tOut = null; GzipCompressorOutputStream gzOut = null; BufferedOutputStream bOut = null; FileOutputStream fOut = null; System.out.println("Creating tarball"); try { File parent = root.getParentFile(); File dst = new File(parent, root.getName() + ".tar.gz"); if (dst.exists()) { dst.delete(); dst.createNewFile(); } String tarGzPath = dst.getAbsolutePath(); fOut = new FileOutputStream(new File(tarGzPath)); bOut = new BufferedOutputStream(fOut); gzOut = new GzipCompressorOutputStream(bOut); tOut = new TarArchiveOutputStream(gzOut); addFilesToTarGz(tOut, root.getAbsolutePath(), ""); return dst; } finally { if (tOut != null) { tOut.finish(); tOut.close(); } if (gzOut != null) gzOut.close(); if (bOut != null) bOut.close(); if (fOut != null) fOut.close(); } }
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();/* w w w . j a v a 2 s .c o m*/ } tarOutput.finish(); tarOutput.close(); os.close(); }