List of usage examples for org.apache.commons.compress.archivers ArchiveStreamFactory TAR
String TAR
To view the source code for org.apache.commons.compress.archivers ArchiveStreamFactory TAR.
Click Source Link
From source file:com.github.wolfposd.jdpkg.deb.DpkgDeb.java
public static void main(String[] args) { if (args.length == 0) { System.out.println("jdpkg-deb: Missing parameters"); System.out.println("jdpkg-deb: Usage: java -jar jdpkg.jar -Zgzip -b SomeFileOrFolder"); System.exit(0);/*from w w w. ja v a2 s.c om*/ } BuildFile = getBuildfile(args); String compressType = getCompressionType(args, "gzip"); if (!new File(BuildFile).exists()) { System.out.println("jdpkg-deb: error: failed to open package info file '" + BuildFile + "/DEBIAN/control' for reading: No such file or directory"); System.exit(0); } switch (compressType) { case "gzip": dpgk_deb(new File(BuildFile), ArchiveStreamFactory.TAR, CompressorStreamFactory.GZIP); break; default: System.out.println("Currently only supports gzip"); break; } }
From source file:fr.gael.dhus.util.UnZip.java
public static void unCompress(String zip_file, String output_folder) throws IOException, CompressorException, ArchiveException { ArchiveInputStream ais = null;/*www.ja v a2 s . c o m*/ ArchiveStreamFactory asf = new ArchiveStreamFactory(); FileInputStream fis = new FileInputStream(new File(zip_file)); if (zip_file.toLowerCase().endsWith(".tar")) { ais = asf.createArchiveInputStream(ArchiveStreamFactory.TAR, fis); } else if (zip_file.toLowerCase().endsWith(".zip")) { ais = asf.createArchiveInputStream(ArchiveStreamFactory.ZIP, fis); } else if (zip_file.toLowerCase().endsWith(".tgz") || zip_file.toLowerCase().endsWith(".tar.gz")) { CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, fis); ais = asf.createArchiveInputStream(new BufferedInputStream(cis)); } else { try { fis.close(); } catch (IOException e) { LOGGER.warn("Cannot close FileInputStream:", e); } throw new IllegalArgumentException("Format not supported: " + zip_file); } File output_file = new File(output_folder); if (!output_file.exists()) output_file.mkdirs(); // copy the existing entries ArchiveEntry nextEntry; while ((nextEntry = ais.getNextEntry()) != null) { File ftemp = new File(output_folder, nextEntry.getName()); if (nextEntry.isDirectory()) { ftemp.mkdir(); } else { FileOutputStream fos = FileUtils.openOutputStream(ftemp); IOUtils.copy(ais, fos); fos.close(); } } ais.close(); fis.close(); }
From source file:net.orpiske.ssps.common.archive.TarArchiveUtils.java
/** * Lower level pack operation//from w w w . j a v a 2s . c o m * * @param source * source file * @param destination * destination file * @return the number of bytes processed * @throws ArchiveException * @throws IOException */ public static long pack(String source, File destination) throws ArchiveException, IOException { ArchiveStreamFactory factory = new ArchiveStreamFactory(); OutputStream outStream = new FileOutputStream(destination); ArchiveOutputStream outputStream; try { outputStream = factory.createArchiveOutputStream(ArchiveStreamFactory.TAR, outStream); } catch (ArchiveException e) { IOUtils.closeQuietly(outStream); throw e; } File startDirectory = new File(source); RecursiveArchiver archiver = new RecursiveArchiver(outputStream); try { archiver.archive(startDirectory); outputStream.flush(); outputStream.close(); outStream.flush(); outStream.close(); } catch (IOException e) { IOUtils.closeQuietly(outStream); IOUtils.closeQuietly(outputStream); throw e; } long ret = outputStream.getBytesWritten(); if (logger.isDebugEnabled()) { logger.debug("Packed " + ret + " bytes"); } return ret; }
From source file:ezbake.deployer.utilities.Utilities.java
public static void appendFilesInTarArchive(OutputStream output, Iterable<ArtifactDataEntry> filesToAdd) throws DeploymentException { ArchiveStreamFactory asf = new ArchiveStreamFactory(); try (GZIPOutputStream gzs = new GZIPOutputStream(output)) { try (ArchiveOutputStream aos = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, gzs)) { for (ArtifactDataEntry entry : filesToAdd) { aos.putArchiveEntry(entry.getEntry()); IOUtils.write(entry.getData(), aos); aos.closeArchiveEntry(); }// ww w.j a v a2s . c om } } catch (ArchiveException e) { log.error(e.getMessage(), e); throw new DeploymentException(e.getMessage()); } catch (IOException e) { log.error(e.getMessage(), e); throw new DeploymentException(e.getMessage()); } }
From source file:com.geewhiz.pacify.model.PArchiveBase.java
public String getType() { String type = getInternalType(); if ("jar".equalsIgnoreCase(type)) { return ArchiveStreamFactory.JAR; }//from w w w .j av a 2s . co m if ("war".equalsIgnoreCase(type)) { return ArchiveStreamFactory.JAR; } if ("ear".equalsIgnoreCase(type)) { return ArchiveStreamFactory.JAR; } if ("zip".equalsIgnoreCase(type)) { return ArchiveStreamFactory.ZIP; } if ("tar".equalsIgnoreCase(type)) { return ArchiveStreamFactory.TAR; } return type; }
From source file:fr.gael.ccsds.sip.archive.TarArchiveManager.java
/** * Produces TAR archive// w w w. ja v a2 s .c om */ @Override public File copy(final File src, final File tar_file, final String dst) throws Exception { final ArchiveStreamFactory asf = new ArchiveStreamFactory(); // Case of tar already exist: all the entries must be copied.. if (tar_file.exists()) { final FileInputStream fis = new FileInputStream(tar_file); final ArchiveInputStream ais = asf.createArchiveInputStream(ArchiveStreamFactory.TAR, fis); final File tempFile = File.createTempFile("updateTar", "tar"); final FileOutputStream fos = new FileOutputStream(tempFile); final ArchiveOutputStream aos = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, fos); // copy the existing entries ArchiveEntry nextEntry; while ((nextEntry = ais.getNextEntry()) != null) { aos.putArchiveEntry(nextEntry); IOUtils.copy(ais, aos); aos.closeArchiveEntry(); } // create the new entry final TarArchiveEntry entry = new TarArchiveEntry(src, dst); entry.setSize(src.length()); aos.putArchiveEntry(entry); final FileInputStream sfis = new FileInputStream(src); IOUtils.copy(sfis, aos); sfis.close(); aos.closeArchiveEntry(); aos.finish(); ais.close(); aos.close(); fis.close(); // copies the new file over the old tar_file.delete(); tempFile.renameTo(tar_file); return tar_file; } else { final FileOutputStream fos = new FileOutputStream(tar_file); final ArchiveOutputStream aos = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, fos); // create the new entry final TarArchiveEntry entry = new TarArchiveEntry(src, dst); entry.setSize(src.length()); aos.putArchiveEntry(entry); final FileInputStream sfis = new FileInputStream(src); IOUtils.copy(sfis, aos); sfis.close(); aos.closeArchiveEntry(); aos.finish(); aos.close(); fos.close(); } return tar_file; }
From source file:fr.gael.ccsds.sip.archive.TgzArchiveManager.java
@Override public File copy(final File src, final File tar_file, final String dst) throws Exception { final ArchiveStreamFactory asf = new ArchiveStreamFactory(); final CompressorStreamFactory csf = new CompressorStreamFactory(); // Case of tar already exist: all the entries must be copied.. if (tar_file.exists()) { final FileInputStream fis = new FileInputStream(tar_file); final CompressorInputStream cis = csf.createCompressorInputStream(CompressorStreamFactory.GZIP, fis); final ArchiveInputStream ais = asf.createArchiveInputStream(ArchiveStreamFactory.TAR, cis); final File tempFile = File.createTempFile("updateTar", "tar"); final FileOutputStream fos = new FileOutputStream(tempFile); final CompressorOutputStream cos = csf.createCompressorOutputStream(CompressorStreamFactory.GZIP, fos); final ArchiveOutputStream aos = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, cos); // copy the existing entries ArchiveEntry nextEntry;//from w w w. j ava2 s . c om while ((nextEntry = ais.getNextEntry()) != null) { aos.putArchiveEntry(nextEntry); IOUtils.copy(ais, aos); aos.closeArchiveEntry(); } // create the new entry final TarArchiveEntry entry = new TarArchiveEntry(src, dst); entry.setSize(src.length()); aos.putArchiveEntry(entry); final FileInputStream sfis = new FileInputStream(src); IOUtils.copy(sfis, aos); sfis.close(); aos.closeArchiveEntry(); aos.finish(); ais.close(); aos.close(); fis.close(); // copies the new file over the old tar_file.delete(); tempFile.renameTo(tar_file); return tar_file; } else { final FileOutputStream fos = new FileOutputStream(tar_file); final CompressorOutputStream cos = csf.createCompressorOutputStream(CompressorStreamFactory.GZIP, fos); final ArchiveOutputStream aos = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, cos); // create the new entry final TarArchiveEntry entry = new TarArchiveEntry(src, dst); entry.setSize(src.length()); aos.putArchiveEntry(entry); final FileInputStream sfis = new FileInputStream(src); IOUtils.copy(sfis, aos); sfis.close(); aos.closeArchiveEntry(); aos.finish(); aos.close(); fos.close(); } return tar_file; }
From source file:com.github.wolfposd.jdpkg.deb.DpkgDeb.java
public static boolean dpgk_deb(File folder, String archivetype, String compressionType) { String packageName = getPackageName(); System.out.println("jdpkg-deb: building package '" + packageName + "' in '" + folder + ".deb'."); File dataTar = new File("data." + archivetype); File dataTarGz = new File(dataTar.getName() + "." + compressionType); File controlTar = new File("control." + archivetype); File controlTarGz = new File(controlTar.getName() + "." + compressionType); File debian_binary = new File("debian-binary"); try {/* w ww. j a va 2 s . com*/ addFilesFromFolderToTar(folder, dataTar, ArchiveStreamFactory.TAR); if (dataTar.exists()) { compressArchive(dataTar, dataTarGz, compressionType); if (dataTarGz.exists()) { dataTar.delete(); } } } catch (IOException | ArchiveException | CompressorException e) { e.printStackTrace(); } try { addFilesFromFolderToTar(new File(folder, "DEBIAN/control"), controlTar, ArchiveStreamFactory.TAR); if (controlTar.exists()) { compressArchive(controlTar, controlTarGz, compressionType); if (controlTarGz.exists()) { controlTar.delete(); } } } catch (IOException | ArchiveException | CompressorException e) { e.printStackTrace(); } writeDebianBuildFile(debian_binary); if (dataTarGz.exists() && controlTarGz.exists()) { try { File debFile = new File(BuildFile + ".deb"); writeDebFile(debFile, new File[] { controlTarGz, dataTarGz, debian_binary }); if (debFile.exists()) { controlTarGz.delete(); dataTarGz.delete(); debian_binary.delete(); } } catch (ArchiveException | IOException e) { e.printStackTrace(); } } return true; }
From source file:com.streamsets.pipeline.lib.parser.TestCompressionInputBuilder.java
@Test public void testArchiveInput() throws Exception { testArchive(ArchiveStreamFactory.TAR); }
From source file:com.geewhiz.pacify.utils.ArchiveUtils.java
public static String getArchiveType(String archiveName) { int idx = archiveName.lastIndexOf("."); String type = archiveName.substring(idx + 1); if ("jar".equalsIgnoreCase(type)) { return ArchiveStreamFactory.JAR; }/*from w w w. j av a 2 s. c om*/ if ("war".equalsIgnoreCase(type)) { return ArchiveStreamFactory.JAR; } if ("ear".equalsIgnoreCase(type)) { return ArchiveStreamFactory.JAR; } if ("zip".equalsIgnoreCase(type)) { return ArchiveStreamFactory.ZIP; } if ("tar".equalsIgnoreCase(type)) { return ArchiveStreamFactory.TAR; } return type; }