List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveEntry setModTime
public void setModTime(Date time)
From source file:org.haiku.haikudepotserver.pkg.job.PkgScreenshotExportArchiveJobRunner.java
private void append(State state, String pkgName, byte[] payload, Date modifyTimestamp, Integer ordering) throws IOException { String filename = String.join("/", PATH_COMPONENT_TOP, pkgName, ordering.toString() + ".png"); TarArchiveEntry tarEntry = new TarArchiveEntry(filename); tarEntry.setSize(payload.length);/*from w w w. j a va2 s .co m*/ tarEntry.setModTime(roundTimeToSecond(modifyTimestamp)); state.tarArchiveOutputStream.putArchiveEntry(tarEntry); state.tarArchiveOutputStream.write(payload); state.tarArchiveOutputStream.closeArchiveEntry(); if (modifyTimestamp.after(state.latestModifiedTimestamp)) { state.latestModifiedTimestamp = modifyTimestamp; } }
From source file:org.jbpm.process.workitem.archive.ArchiveWorkItemHandler.java
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { String archive = (String) workItem.getParameter("Archive"); List<File> files = (List<File>) workItem.getParameter("Files"); try {/*w w w.ja v a 2 s .c o m*/ OutputStream outputStream = new FileOutputStream(new File(archive)); ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("tar", outputStream); if (files != null) { for (File file : files) { final TarArchiveEntry entry = new TarArchiveEntry("testdata/test1.xml"); entry.setModTime(0); entry.setSize(file.length()); entry.setUserId(0); entry.setGroupId(0); entry.setMode(0100000); os.putArchiveEntry(entry); IOUtils.copy(new FileInputStream(file), os); } } os.closeArchiveEntry(); os.close(); manager.completeWorkItem(workItem.getId(), null); } catch (Throwable t) { t.printStackTrace(); manager.abortWorkItem(workItem.getId()); } }
From source file:org.kitesdk.cli.commands.TestTarImportCommand.java
private static void writeToTarFile(TarArchiveOutputStream tos, String name, String content) throws IOException { TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name); if (null != content) { tarArchiveEntry.setSize(content.length()); }/* w w w .j a v a2s. c o m*/ tarArchiveEntry.setModTime(System.currentTimeMillis()); tos.putArchiveEntry(tarArchiveEntry); if (null != content) { byte[] buf = content.getBytes(); tos.write(buf, 0, content.length()); tos.flush(); } tos.closeArchiveEntry(); }
From source file:org.savantbuild.io.tar.TarBuilder.java
/** * Builds the TAR file using the fileSets and Directories provided. * * @return The number of entries added to the TAR file including the directories. * @throws IOException If the build fails. *//*from w ww . j ava 2 s . c o m*/ public int build() throws IOException { if (Files.exists(file)) { Files.delete(file); } if (!Files.isDirectory(file.getParent())) { Files.createDirectories(file.getParent()); } // Sort the file infos and add the directories Set<FileInfo> fileInfos = new TreeSet<>(); for (FileSet fileSet : fileSets) { Set<Directory> dirs = fileSet.toDirectories(); dirs.removeAll(directories); for (Directory dir : dirs) { directories.add(dir); } fileInfos.addAll(fileSet.toFileInfos()); } int count = 0; OutputStream os = Files.newOutputStream(file); try (TarArchiveOutputStream tos = new TarArchiveOutputStream(compress ? new GZIPOutputStream(os) : os)) { tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (Directory directory : directories) { String name = directory.name; TarArchiveEntry entry = new TarArchiveEntry(name.endsWith("/") ? name : name + "/"); if (directory.lastModifiedTime != null) { entry.setModTime(directory.lastModifiedTime.toMillis()); } if (directory.mode != null) { entry.setMode(FileTools.toMode(directory.mode)); } if (storeGroupName && directory.groupName != null) { entry.setGroupName(directory.groupName); } if (storeUserName && directory.userName != null) { entry.setUserName(directory.userName); } tos.putArchiveEntry(entry); tos.closeArchiveEntry(); count++; } for (FileInfo fileInfo : fileInfos) { TarArchiveEntry entry = new TarArchiveEntry(fileInfo.relative.toString()); entry.setModTime(fileInfo.lastModifiedTime.toMillis()); if (storeGroupName) { entry.setGroupName(fileInfo.groupName); } if (storeUserName) { entry.setUserName(fileInfo.userName); } entry.setSize(fileInfo.size); entry.setMode(fileInfo.toMode()); tos.putArchiveEntry(entry); Files.copy(fileInfo.origin, tos); tos.closeArchiveEntry(); count++; } } return count; }
From source file:org.torproject.collector.bridgedescs.TarballBuilder.java
/** Writes the previously configured tarball with all contained files to the * given file, or fail if the file extension is not known. */ void build(File directory) throws IOException { File tarballFile = new File(directory, this.tarballFileName); TarArchiveOutputStream taos = null;/*from www. jav a 2s . co m*/ if (this.tarballFileName.endsWith(".tar.gz")) { taos = new TarArchiveOutputStream( new GzipCompressorOutputStream(new BufferedOutputStream(new FileOutputStream(tarballFile)))); } else if (this.tarballFileName.endsWith(".tar.bz2")) { taos = new TarArchiveOutputStream( new BZip2CompressorOutputStream(new BufferedOutputStream(new FileOutputStream(tarballFile)))); } else if (this.tarballFileName.endsWith(".tar")) { taos = new TarArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(tarballFile))); } else { fail("Unknown file extension: " + this.tarballFileName); } for (Map.Entry<String, TarballFile> file : this.tarballFiles.entrySet()) { TarArchiveEntry tae = new TarArchiveEntry(file.getKey()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (DescriptorBuilder descriptorBuilder : file.getValue().descriptorBuilders) { descriptorBuilder.build(baos); } tae.setSize(baos.size()); tae.setModTime(file.getValue().modifiedMillis); taos.putArchiveEntry(tae); taos.write(baos.toByteArray()); taos.closeArchiveEntry(); } taos.close(); tarballFile.setLastModified(this.modifiedMillis); }
From source file:org.vafer.jdeb.producers.DataProducerArchive.java
public void produce(final DataConsumer pReceiver) throws IOException { InputStream is = new BufferedInputStream(new FileInputStream(archive)); CompressorInputStream compressorInputStream = null; try {//from www. j av a 2 s .c om compressorInputStream = new CompressorStreamFactory().createCompressorInputStream(is); } catch (CompressorException e) { // expected if the input file is a zip archive } if (compressorInputStream != null) { is = new BufferedInputStream(compressorInputStream); } ArchiveInputStream archiveInputStream = null; try { archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream(is); } catch (ArchiveException e) { throw new IOException("Unsupported archive format: " + archive, e); } EntryConverter converter = null; if (archiveInputStream instanceof TarArchiveInputStream) { converter = new EntryConverter() { public TarArchiveEntry convert(ArchiveEntry entry) { TarArchiveEntry src = (TarArchiveEntry) entry; TarArchiveEntry dst = new TarArchiveEntry(src.getName(), true); dst.setSize(src.getSize()); dst.setGroupName(src.getGroupName()); dst.setGroupId(src.getGroupId()); dst.setUserId(src.getUserId()); dst.setMode(src.getMode()); dst.setModTime(src.getModTime()); return dst; } }; } else if (archiveInputStream instanceof ZipArchiveInputStream) { converter = new EntryConverter() { public TarArchiveEntry convert(ArchiveEntry entry) { ZipArchiveEntry src = (ZipArchiveEntry) entry; TarArchiveEntry dst = new TarArchiveEntry(src.getName(), true); dst.setSize(src.getSize()); dst.setMode(src.getUnixMode()); dst.setModTime(src.getTime()); return dst; } }; } else { throw new IOException("Unsupported archive format: " + archive); } try { while (true) { ArchiveEntry archiveEntry = archiveInputStream.getNextEntry(); if (archiveEntry == null) { break; } if (!isIncluded(archiveEntry.getName())) { continue; } TarArchiveEntry entry = converter.convert(archiveEntry); entry = map(entry); if (entry.isDirectory()) { pReceiver.onEachDir(entry.getName(), entry.getLinkName(), entry.getUserName(), entry.getUserId(), entry.getGroupName(), entry.getGroupId(), entry.getMode(), entry.getSize()); continue; } pReceiver.onEachFile(archiveInputStream, entry.getName(), entry.getLinkName(), entry.getUserName(), entry.getUserId(), entry.getGroupName(), entry.getGroupId(), entry.getMode(), entry.getSize()); } } finally { if (archiveInputStream != null) { archiveInputStream.close(); } } }