List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream TarArchiveOutputStream
public TarArchiveOutputStream(OutputStream os)
From source file:gov.nih.nci.nbia.servlet.DownloadServletV2.java
private void sendResponse(HttpServletResponse response, List<ImageDTO2> imageResults, List<AnnotationDTO> annoResults) throws IOException { TarArchiveOutputStream tos = new TarArchiveOutputStream(response.getOutputStream()); try {//from ww w . j av a2 s. com long start = System.currentTimeMillis(); logger.info("images size: " + imageResults.size() + " anno size: " + annoResults.size()); sendAnnotationData(annoResults, tos); sendImagesData(imageResults, tos); logger.info("total time to send files are " + (System.currentTimeMillis() - start) / 1000 + " ms."); } finally { IOUtils.closeQuietly(tos); } }
From source file:com.flurry.proguard.UploadMapping.java
/** * Create a gzipped tar archive containing the ProGuard/Native mapping files * * @param files array of mapping.txt files * @return the tar-gzipped archive//from w w w.j av a 2s .com */ private static File createArchive(List<File> files, String uuid) { try { File tarZippedFile = File.createTempFile("tar-zipped-file", ".tgz"); TarArchiveOutputStream taos = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(tarZippedFile)))); for (File file : files) { taos.putArchiveEntry(new TarArchiveEntry(file, (uuid != null && !uuid.isEmpty() ? uuid : UUID.randomUUID()) + ".txt")); IOUtils.copy(new FileInputStream(file), taos); taos.closeArchiveEntry(); } taos.finish(); taos.close(); return tarZippedFile; } catch (IOException e) { failWithError("IO Exception while trying to tar and zip the file.", e); return null; } }
From source file:com.vmware.admiral.closures.util.ClosureUtils.java
private static TarArchiveOutputStream buildTarStream(OutputStream outputStream) throws IOException { OutputStream bufferedOutputStream = new BufferedOutputStream(outputStream); bufferedOutputStream = new GzipCompressorOutputStream(bufferedOutputStream); TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream(bufferedOutputStream); tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); return tarArchiveOutputStream; }
From source file:deployer.TestUtils.java
public static ByteBuffer createSampleOpenShiftWebAppTarBall() throws IOException, ArchiveException { ByteArrayInputStream bis = new ByteArrayInputStream(createSampleAppTarBall(ArtifactType.WebApp).array()); CompressorInputStream cis = new GzipCompressorInputStream(bis); ArchiveInputStream ais = new TarArchiveInputStream(cis); ByteArrayOutputStream bos = new ByteArrayOutputStream(bis.available() + 2048); CompressorOutputStream cos = new GzipCompressorOutputStream(bos); ArchiveOutputStream aos = new TarArchiveOutputStream(cos); ArchiveEntry nextEntry;// ww w . j av a2 s.co m while ((nextEntry = ais.getNextEntry()) != null) { aos.putArchiveEntry(nextEntry); IOUtils.copy(ais, aos); aos.closeArchiveEntry(); } ais.close(); cis.close(); bis.close(); TarArchiveEntry entry = new TarArchiveEntry( Paths.get(".openshift", CONFIG_DIRECTORY, "/standalone.xml").toFile()); byte[] xmlData = SAMPLE_STANDALONE_DATA.getBytes(); entry.setSize(xmlData.length); aos.putArchiveEntry(entry); IOUtils.write(xmlData, aos); aos.closeArchiveEntry(); aos.finish(); cos.close(); bos.flush(); return ByteBuffer.wrap(bos.toByteArray()); }
From source file:gzipper.algorithms.Gzip.java
@Override public void run() { /*check whether archive with given name already exists; if so, add index to file name an re-check*/ if (_createArchive) { try {/* w ww . jav a 2 s.c o m*/ File file = new File(_path + _archiveName + ".tar.gz"); while (file.exists()) { ++_nameIndex; _archiveName = _archiveName.substring(0, 7) + _nameIndex; file = new File(_path + _archiveName + ".tar.gz"); } _tos = new TarArchiveOutputStream(new GZIPOutputStream( new BufferedOutputStream(new FileOutputStream(_path + _archiveName + ".tar.gz")))); _tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); _tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); } catch (IOException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, "Error creating output stream", ex); System.exit(1); } } while (_runFlag) { try { long startTime = System.nanoTime(); if (_selectedFiles != null) { if (_createArchive != false) { compress(_selectedFiles, ""); } else { extract(_path, _archiveName); } } else { throw new GZipperException("File selection must not be null"); } _elapsedTime = System.nanoTime() - startTime; } catch (IOException | GZipperException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, "Error compressing archive", ex); } finally { stop(); //stop thread after successful operation } } }
From source file:io.syndesis.project.converter.DefaultProjectGenerator.java
private Runnable generateAddProjectTarEntries(GenerateProjectRequest request, OutputStream os) { return () -> { try (TarArchiveOutputStream tos = new TarArchiveOutputStream(os)) { tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); addTarEntry(tos, "src/main/java/io/syndesis/example/Application.java", generateFromRequest(request, applicationJavaMustache)); addTarEntry(tos, "src/main/resources/application.properties", generateFromRequest(request, applicationPropertiesMustache)); addTarEntry(tos, "src/main/resources/syndesis.yml", generateFlowYaml(tos, request)); addTarEntry(tos, "pom.xml", generatePom(request.getIntegration())); addAdditionalResources(tos); LOG.info("Integration [{}]: Project files written to output stream", Names.sanitize(request.getIntegration().getName())); } catch (IOException e) { if (LOG.isErrorEnabled()) { LOG.error(String.format("Exception while creating runtime build tar for integration %s : %s", request.getIntegration().getName(), e.toString()), e); }// w ww .j a v a2 s . com } }; }
From source file:com.gitblit.utils.CompressionUtils.java
/** * Compresses/archives the contents of the tree at the (optionally) * specified revision and the (optionally) specified basepath to the * supplied outputstream.//from w w w . j a v a2 s . c o m * * @param algorithm * compression algorithm for tar (optional) * @param repository * @param basePath * if unspecified, entire repository is assumed. * @param objectId * if unspecified, HEAD is assumed. * @param os * @return true if repository was successfully zipped to supplied output * stream */ private static boolean tar(String algorithm, Repository repository, String basePath, String objectId, OutputStream os) { RevCommit commit = JGitUtils.getCommit(repository, objectId); if (commit == null) { return false; } OutputStream cos = os; if (!StringUtils.isEmpty(algorithm)) { try { cos = new CompressorStreamFactory().createCompressorOutputStream(algorithm, os); } catch (CompressorException e1) { error(e1, repository, "{0} failed to open {1} stream", algorithm); } } boolean success = false; RevWalk rw = new RevWalk(repository); TreeWalk tw = new TreeWalk(repository); try { tw.reset(); tw.addTree(commit.getTree()); TarArchiveOutputStream tos = new TarArchiveOutputStream(cos); tos.setAddPaxHeadersForNonAsciiNames(true); tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); if (!StringUtils.isEmpty(basePath)) { PathFilter f = PathFilter.create(basePath); tw.setFilter(f); } tw.setRecursive(true); MutableObjectId id = new MutableObjectId(); long modified = commit.getAuthorIdent().getWhen().getTime(); while (tw.next()) { FileMode mode = tw.getFileMode(0); if (mode == FileMode.GITLINK || mode == FileMode.TREE) { continue; } tw.getObjectId(id, 0); ObjectLoader loader = repository.open(id); if (FileMode.SYMLINK == mode) { TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString(), TarArchiveEntry.LF_SYMLINK); ByteArrayOutputStream bos = new ByteArrayOutputStream(); loader.copyTo(bos); entry.setLinkName(bos.toString()); entry.setModTime(modified); tos.putArchiveEntry(entry); tos.closeArchiveEntry(); } else { TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString()); entry.setMode(mode.getBits()); entry.setModTime(modified); entry.setSize(loader.getSize()); tos.putArchiveEntry(entry); loader.copyTo(tos); tos.closeArchiveEntry(); } } tos.finish(); tos.close(); cos.close(); success = true; } catch (IOException e) { error(e, repository, "{0} failed to {1} stream files from commit {2}", algorithm, commit.getName()); } finally { tw.release(); rw.dispose(); } return success; }
From source file:deployer.TestUtils.java
public static ByteBuffer createSampleOpenShiftWebAppTarBallWithEmptyFiles(String[] filepaths) throws IOException, ArchiveException { ByteArrayInputStream bis = new ByteArrayInputStream(createSampleAppTarBall(ArtifactType.WebApp).array()); CompressorInputStream cis = new GzipCompressorInputStream(bis); ArchiveInputStream ais = new TarArchiveInputStream(cis); ByteArrayOutputStream bos = new ByteArrayOutputStream(bis.available() + 2048); CompressorOutputStream cos = new GzipCompressorOutputStream(bos); ArchiveOutputStream aos = new TarArchiveOutputStream(cos); ArchiveEntry nextEntry;/*from w w w . java2 s . c o m*/ while ((nextEntry = ais.getNextEntry()) != null) { aos.putArchiveEntry(nextEntry); IOUtils.copy(ais, aos); aos.closeArchiveEntry(); } ais.close(); cis.close(); bis.close(); TarArchiveEntry entry = new TarArchiveEntry( Paths.get(".openshift", CONFIG_DIRECTORY, "/standalone.xml").toFile()); byte[] xmlData = SAMPLE_STANDALONE_DATA.getBytes(); entry.setSize(xmlData.length); aos.putArchiveEntry(entry); IOUtils.write(xmlData, aos); for (int i = 0; i < filepaths.length; i++) { String filepath = filepaths[i]; TarArchiveEntry emptyEntry = new TarArchiveEntry(Paths.get(filepath).toFile()); byte[] emptyData = "".getBytes(); emptyEntry.setSize(emptyData.length); aos.putArchiveEntry(emptyEntry); IOUtils.write(emptyData, aos); aos.closeArchiveEntry(); } aos.finish(); cos.close(); bos.flush(); return ByteBuffer.wrap(bos.toByteArray()); }
From source file:com.mobilesorcery.sdk.builder.linux.deb.DebBuilder.java
/** * * @param os//from ww w . j av a 2s .c o m * @throws IOException */ private void doCreateControlTarGZip(File f) throws Exception { File ftemp; FileOutputStream os = new FileOutputStream(f); GzipCompressorOutputStream gzos = new GzipCompressorOutputStream(os); TarArchiveOutputStream tos = new TarArchiveOutputStream(gzos); // Write control file ftemp = File.createTempFile(System.currentTimeMillis() + "", "control"); doWriteControl(ftemp); tos.putArchiveEntry(new TarArchiveEntry(ftemp, "./control")); BuilderUtil.getInstance().copyFileToOutputStream(tos, ftemp); tos.closeArchiveEntry(); ftemp.delete(); // Write md5sums ftemp = File.createTempFile(System.currentTimeMillis() + "", "md5sums"); doWriteMD5SumsToFile(ftemp); tos.putArchiveEntry(new TarArchiveEntry(ftemp, "./md5sums")); BuilderUtil.getInstance().copyFileToOutputStream(tos, ftemp); tos.closeArchiveEntry(); ftemp.delete(); // Add prerm, postrm, preinst, postinst scripts for (Entry<String, String> s : m_scriptMap.entrySet()) { TarArchiveEntry e = new TarArchiveEntry("./" + s.getKey()); e.setSize(s.getValue().length()); tos.putArchiveEntry(e); BuilderUtil.getInstance().copyStringToOutputStream(tos, s.getValue()); tos.closeArchiveEntry(); } // Done tos.close(); gzos.close(); os.close(); }
From source file:co.cask.cdap.internal.app.runtime.LocalizationUtilsTest.java
private File createTarFile(String tarFileName, File... filesToAdd) throws IOException { File target = TEMP_FOLDER.newFile(tarFileName + ".tar"); try (TarArchiveOutputStream tos = new TarArchiveOutputStream( new BufferedOutputStream(new FileOutputStream(target)))) { addFilesToTar(tos, filesToAdd);/*from w w w .j av a 2s. c o m*/ } return target; }