List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveEntry setSize
public void setSize(long size)
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;/* w w w . j a va 2s .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); aos.closeArchiveEntry(); aos.finish(); cos.close(); bos.flush(); return ByteBuffer.wrap(bos.toByteArray()); }
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 ww w .jav a2s . com 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:frameworks.Masken.java
public static void addFileToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException { File f = new File(path); System.out.println(f.exists()); //tmp wegschneiden if (base.startsWith("tmp")) { base = base.substring(4, base.length()); }/*from w w w.j a va 2s .c om*/ String entryName = base + f.getName(); TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName); tarEntry.setSize(f.length()); tOut.putArchiveEntry(tarEntry); if (f.isFile()) { IOUtils.copy(new FileInputStream(f), tOut); // FileInputStream in = new FileInputStream(f); // IOUtils.copy(in, tOut); // in.close(); } else { tOut.closeArchiveEntry(); File[] children = f.listFiles(); if (children != null) { for (File child : children) { System.out.println(child.getName()); if (!child.getName().startsWith("screen.")) { addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/"); } } } } }
From source file:frameworks.Masken.java
public static void createTarGzip(String dirPath, String tarGzPath) throws IOException { File inputDirectoryPath = new File(dirPath); File outputFile = new File(tarGzPath); try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream); GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(bufferedOutputStream); TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream(gzipOutputStream)) { tarArchiveOutputStream.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX); tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); List<File> files = new ArrayList<>(FileUtils.listFiles(inputDirectoryPath, new RegexFileFilter("^(.*?)"), DirectoryFileFilter.DIRECTORY)); for (int i = 0; i < files.size(); i++) { File currentFile = files.get(i); if (!currentFile.getName().contains(".tgz")) { String relativeFilePath = new File(inputDirectoryPath.toURI()).toURI() .relativize(new File(currentFile.getAbsolutePath()).toURI()).getPath(); TarArchiveEntry tarEntry = new TarArchiveEntry(currentFile, relativeFilePath); tarEntry.setSize(currentFile.length()); tarArchiveOutputStream.putArchiveEntry(tarEntry); FileInputStream in = new FileInputStream(currentFile); //tarArchiveOutputStream.write(IOUtils.toByteArray(new FileInputStream(currentFile))); tarArchiveOutputStream.write(IOUtils.toByteArray(in)); tarArchiveOutputStream.closeArchiveEntry(); in.close();// w ww . jav a 2s. com } } tarArchiveOutputStream.close(); } }
From source file:lucee.commons.io.compress.CompressUtil.java
private static void compressTar(String parent, Resource source, TarArchiveOutputStream tos, int mode) throws IOException { if (source.isFile()) { //TarEntry entry = (source instanceof FileResource)?new TarEntry((FileResource)source):new TarEntry(parent); TarArchiveEntry entry = new TarArchiveEntry(parent); entry.setName(parent);//from www . j ava 2 s. c o m // mode //100777 TODO ist das so ok? if (mode > 0) entry.setMode(mode); else if ((mode = source.getMode()) > 0) entry.setMode(mode); entry.setSize(source.length()); entry.setModTime(source.lastModified()); tos.putArchiveEntry(entry); try { IOUtil.copy(source, tos, false); } finally { tos.closeArchiveEntry(); } } else if (source.isDirectory()) { compressTar(parent, source.listResources(), tos, mode); } }
From source file:cpcc.vvrte.services.VirtualVehicleMigratorTest.java
private static void appendEntryToStream(String entryName, byte[] content, ArchiveOutputStream os) throws IOException { TarArchiveEntry entry = new TarArchiveEntry(entryName); entry.setModTime(new Date()); entry.setSize(content.length); entry.setIds(0, 0);// w w w.j a v a 2 s . c o m entry.setNames("vvrte", "cpcc"); os.putArchiveEntry(entry); os.write(content); os.closeArchiveEntry(); }
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./* www.j a va 2s .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:io.syndesis.project.converter.visitor.GeneratorContext.java
default void addTarEntry(String path, byte[] content) throws IOException { TarArchiveOutputStream tos = getTarArchiveOutputStream(); TarArchiveEntry entry = new TarArchiveEntry(path); entry.setSize(content.length); tos.putArchiveEntry(entry);/*from ww w. jav a2s . c om*/ tos.write(content); tos.closeArchiveEntry(); }
From source file:com.ibm.util.merge.storage.TarArchive.java
@Override public String writeFile(String entryName, String content, String userName, String groupName) throws IOException, MergeException { String chksum = super.writeFile(entryName, content, userName, groupName); TarArchiveOutputStream outputStream = (TarArchiveOutputStream) this.getOutputStream(); TarArchiveEntry entry = new TarArchiveEntry(entryName); entry.setSize(content.getBytes().length); entry.setNames(userName, groupName); outputStream.putArchiveEntry(entry); outputStream.write(content.getBytes()); outputStream.flush();/*from ww w . j a v a2s.co m*/ outputStream.closeArchiveEntry(); return chksum; }
From source file:br.com.thiaguten.archive.TarArchive.java
@Override protected ArchiveEntry createArchiveEntry(String path, long size, byte[] content) { TarArchiveEntry tarEntry = new TarArchiveEntry(path); tarEntry.setSize(size); return tarEntry; }