use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project che by eclipse.
the class TarArchiverTest method createTestTarArchive.
private byte[] createTestTarArchive() throws IOException {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
TarArchiveOutputStream tarOut = new TarArchiveOutputStream(byteOut);
addDirectoryEntry(tarOut, new TarArchiveEntry("arc/"));
addDirectoryEntry(tarOut, new TarArchiveEntry("arc/a/"));
addFileEntry(tarOut, "arc/a/_a.txt");
addDirectoryEntry(tarOut, new TarArchiveEntry("arc/b/"));
addFileEntry(tarOut, "arc/b/_b.txt");
addDirectoryEntry(tarOut, new TarArchiveEntry("arc/c/"));
addFileEntry(tarOut, "arc/c/_c.txt");
tarOut.close();
return byteOut.toByteArray();
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project che by eclipse.
the class TarArchiver method addTarEntry.
private void addTarEntry(VirtualFile virtualFile, TarArchiveOutputStream tarOutputStream) throws ServerException {
try {
TarArchiveEntry tarEntry = new TarArchiveEntry(getTarEntryName(virtualFile));
if (virtualFile.isFolder()) {
tarEntry.setModTime(0);
tarOutputStream.putArchiveEntry(tarEntry);
} else {
tarEntry.setSize(virtualFile.getLength());
tarEntry.setModTime(virtualFile.getLastModificationDate());
tarOutputStream.putArchiveEntry(tarEntry);
try (InputStream content = virtualFile.getContent()) {
ByteStreams.copy(content, tarOutputStream);
}
}
tarOutputStream.closeArchiveEntry();
} catch (ForbiddenException e) {
throw new ServerException(e.getServiceError());
} catch (IOException e) {
throw new ServerException(e.getMessage(), e);
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project tdi-studio-se by Talend.
the class Zip method doTarGZip.
private void doTarGZip(Map<String, File> filesMap) throws Exception {
File targetFile = new File(targetZip);
targetFile.setLastModified(System.currentTimeMillis());
FileOutputStream fos = new FileOutputStream(targetFile);
final boolean syncFlush = this.syncFlush;
final int compressLevel = this.compressLevel;
TarArchiveOutputStream taos = new TarArchiveOutputStream(new GZIPOutputStream(fos, syncFlush) {
{
this.def.setLevel(compressLevel);
}
});
taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
try {
for (String relativeDir : filesMap.keySet()) {
File file = filesMap.get(relativeDir);
taos.putArchiveEntry(new TarArchiveEntry(file, relativeDir));
FileInputStream is = new FileInputStream(file);
try {
IOUtils.copy(is, taos);
taos.closeArchiveEntry();
} finally {
is.close();
}
}
} finally {
taos.close();
fos.close();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project gerrit by GerritCodeReview.
the class SubmitByMergeIfNecessaryIT method testPreviewSubmitTgz.
@Test
public void testPreviewSubmitTgz() throws Exception {
Project.NameKey p1 = createProject("project-name");
TestRepository<?> repo1 = cloneProject(p1);
PushOneCommit.Result change1 = createChange(repo1, "master", "test", "a.txt", "1", "topic");
approve(change1.getChangeId());
// get a preview before submitting:
File tempfile;
try (BinaryResult request = submitPreview(change1.getChangeId(), "tgz")) {
assertThat(request.getContentType()).isEqualTo("application/x-gzip");
tempfile = File.createTempFile("test", null);
request.writeTo(Files.newOutputStream(tempfile.toPath()));
}
InputStream is = new GZIPInputStream(Files.newInputStream(tempfile.toPath()));
List<String> untarredFiles = new ArrayList<>();
try (TarArchiveInputStream tarInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is)) {
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) {
untarredFiles.add(entry.getName());
}
}
assertThat(untarredFiles).containsExactly(name("project-name") + ".git");
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project karaf by apache.
the class ArchiveMojo method addFileToTarGz.
private void addFileToTarGz(TarArchiveOutputStream tOut, Path f, String base) throws IOException {
if (Files.isDirectory(f)) {
String entryName = base + f.getFileName().toString() + "/";
TarArchiveEntry tarEntry = new TarArchiveEntry(entryName);
tOut.putArchiveEntry(tarEntry);
tOut.closeArchiveEntry();
try (DirectoryStream<Path> children = Files.newDirectoryStream(f)) {
for (Path child : children) {
addFileToTarGz(tOut, child, entryName);
}
}
} else if (useSymLinks && Files.isSymbolicLink(f)) {
String entryName = base + f.getFileName().toString();
TarArchiveEntry tarEntry = new TarArchiveEntry(entryName, TarConstants.LF_SYMLINK);
tarEntry.setLinkName(Files.readSymbolicLink(f).toString());
tOut.putArchiveEntry(tarEntry);
tOut.closeArchiveEntry();
} else {
String entryName = base + f.getFileName().toString();
TarArchiveEntry tarEntry = new TarArchiveEntry(entryName);
tarEntry.setSize(Files.size(f));
if (entryName.contains("/bin/") || (!usePathPrefix && entryName.startsWith("bin/"))) {
if (entryName.endsWith(".bat")) {
tarEntry.setMode(0644);
} else {
tarEntry.setMode(0755);
}
}
tOut.putArchiveEntry(tarEntry);
Files.copy(f, tOut);
tOut.closeArchiveEntry();
}
}
Aggregations