@RequestMapping(path = "/starter.tgz", produces = "application/x-compress") @ResponseBody public ResponseEntity<byte[]> springTgz(BasicProjectRequest basicRequest) throws IOException { ProjectRequest request = (ProjectRequest) basicRequest; File dir = this.projectGenerator.generateProjectStructure(request); File download = this.projectGenerator.createDistributionFile(dir, ".tar.gz"); String wrapperScript = getWrapperScript(request); new File(dir, wrapperScript).setExecutable(true); Tar zip = new Tar(); zip.setProject(new Project()); zip.setDefaultexcludes(false); TarFileSet set = zip.createTarFileSet(); set.setDir(dir); set.setFileMode("755"); set.setIncludes(wrapperScript); set.setDefaultexcludes(false); set = zip.createTarFileSet(); set.setDir(dir); set.setIncludes("**,"); set.setExcludes(wrapperScript); set.setDefaultexcludes(false); zip.setDestFile(download.getCanonicalFile()); Tar.TarCompressionMethod method = new Tar.TarCompressionMethod(); method.setValue("gzip"); zip.setCompression(method); zip.execute(); return upload(download, dir, generateFileName(request, "tar.gz"), "application/x-compress"); }
/** * This method wraps the output stream with the * corresponding compression method * * @param ostream output stream * @return output stream with on-the-fly compression * @exception IOException thrown if file is not writable */ private OutputStream compress(final OutputStream ostream) throws IOException { final String v = getValue(); if (GZIP.equals(v)) { return new GZIPOutputStream(ostream); } if (XZ.equals(v)) { return newXZOutputStream(ostream); } if (BZIP2.equals(v)) { ostream.write('B'); ostream.write('Z'); return new CBZip2OutputStream(ostream); } return ostream; }
if ("tar.gz".equals(artifact.getType())) { Tar tar = new Tar(); Tar.TarCompressionMethod tarCompressionMethod = new Tar.TarCompressionMethod(); tarCompressionMethod.setValue("gzip"); tar.setCompression(tarCompressionMethod); Tar.TarLongFileMode fileMode = new Tar.TarLongFileMode();
private void bzipTestResults(File dir) { File destFile = new File(dir, "results.tar.bz2"); Tar bzipTask = new Tar(); Tar.TarCompressionMethod bzip2 = new Tar.TarCompressionMethod(); bzip2.setValue("bzip2"); bzipTask.setCompression(bzip2); bzipTask.setProject(new Project()); bzipTask.setDestFile(destFile); FileSet fs = bzipTask.createTarFileSet(); fs.setDir(dir); fs.setIncludes("*.html"); bzipTask.execute(); log.info("bzipped test results: " + destFile.getAbsolutePath()); }
private TarCompressionMethod getCompressionMethod() { TarCompressionMethod method = new TarCompressionMethod(); method.setValue(getCompressionMode()); return method; }
/** * Default constructor */ public TarCompressionMethod() { super(); setValue(NONE); }