List of usage examples for org.apache.commons.compress.archivers ArchiveOutputStream putArchiveEntry
public abstract void putArchiveEntry(ArchiveEntry entry) throws IOException;
From source file:org.eclipse.winery.repository.export.ZipExporter.java
private CustomizedFileInfos exportFiles(List<FileInfo> fileInfos, ArchiveOutputStream aos) throws IOException { CustomizedFileInfos result = new CustomizedFileInfos(); for (FileInfo fileInfo : fileInfos) { String filePath = getRelativePath(fileInfo); if (filePath.startsWith("plan")) { result.addPlanInfo(fileInfo); } else {//w w w . ja va 2s.co m String md5 = null; aos.putArchiveEntry(new ZipArchiveEntry(filePath)); try (InputStream is = Repository.INSTANCE.newInputStream(fileInfo.getRef())) { md5 = MD5Util.md5(is, aos); } catch (Exception e) { ZipExporter.logger.error("Could not copy file content to ZIP outputstream", e); } aos.closeArchiveEntry(); CustomFileResultInfo info = new CustomFileResultInfo(); info.setFileFullName(filePath); info.setFileChecksum(md5); result.addCustFileInfo(info); } } return result; }
From source file:org.eclipse.winery.repository.export.ZipExporter.java
private void addCheckSumFest(String[] checksums, ArchiveOutputStream out) throws IOException { out.putArchiveEntry(new ZipArchiveEntry("checksum.lst")); PrintWriter pw = new PrintWriter(out); for (String checksum : checksums) { pw.println(checksum);//from w w w. jav a 2 s . co m } pw.flush(); out.closeArchiveEntry(); }
From source file:org.eclipse.winery.repository.export.ZipExporter.java
/** * Writes the configured mapping namespaceprefix -> namespace to the archive * // www. j a va 2 s.com * This is kind of a quick hack. TODO: during the import, the prefixes should be extracted using * JAXB and stored in the NamespacesResource * * @throws IOException */ private void addNamespacePrefixes(ArchiveOutputStream zos) throws IOException { Configuration configuration = Repository.INSTANCE.getConfiguration(new NamespacesId()); if (configuration instanceof PropertiesConfiguration) { // Quick hack: direct serialization only works for PropertiesConfiguration PropertiesConfiguration pconf = (PropertiesConfiguration) configuration; ArchiveEntry archiveEntry = new ZipArchiveEntry(ZipExporter.PATH_TO_NAMESPACES_PROPERTIES); zos.putArchiveEntry(archiveEntry); try { pconf.save(zos); } catch (ConfigurationException e) { ZipExporter.logger.debug(e.getMessage(), e); zos.write("#Could not export properties".getBytes()); zos.write(("#" + e.getMessage()).getBytes()); } zos.closeArchiveEntry(); } }
From source file:org.eclipse.winery.repository.export.ZipExporter.java
private void addCsarMeta(ServiceTemplateId entryId, ArchiveOutputStream out) throws IOException { AbstractComponentInstanceResource res = AbstractComponentsResource.getComponentInstaceResource(entryId); Definitions entryDefinitions = res.getDefinitions(); TServiceTemplate serviceTemplate = (TServiceTemplate) entryDefinitions .getServiceTemplateOrNodeTypeOrNodeTypeImplementation().get(0); out.putArchiveEntry(new ZipArchiveEntry("csar.meta")); BoundaryPropertyDefinition boundaryPropertyDefinition = BoundaryPropertyUtil .getBoundaryPropertyDefinition(serviceTemplate.getBoundaryDefinitions().getProperties().getAny()); StringBuffer buffer = new StringBuffer(); buffer.append("Type:"); buffer.append(boundaryPropertyDefinition.getMetaData("csarType")); buffer.append("\n"); buffer.append("Version:"); buffer.append(boundaryPropertyDefinition.getMetaData("csarVersion")); buffer.append("\n"); buffer.append("Provider:"); buffer.append(boundaryPropertyDefinition.getMetaData("csarProvider")); PrintWriter pw = new PrintWriter(out); pw.print(buffer.toString());//from w w w .j a va2s . c o m pw.flush(); out.closeArchiveEntry(); }
From source file:org.eclipse.winery.repository.export.ZipExporter.java
private void addManifest(TOSCAComponentId id, Collection<String> definitionNames, Map<RepositoryFileReference, String> refMap, ArchiveOutputStream out) throws IOException { String entryDefinitionsReference = ZipExporter.getDefinitionsPathInsideCSAR(id); out.putArchiveEntry(new ZipArchiveEntry("xml/TOSCA-Metadata/TOSCA.meta")); PrintWriter pw = new PrintWriter(out); // Setting Versions pw.println("TOSCA-Meta-Version: 1.0"); pw.println("CSAR-Version: 1.0"); String versionString = "Created-By: Winery " + Prefs.INSTANCE.getVersion(); pw.println(versionString);//from w w w.j a v a 2 s. c o m // Winery currently is unaware of tDefinitions, therefore, we use the // name of the service template pw.println("Entry-Definitions: " + entryDefinitionsReference); pw.println(); assert (definitionNames.contains(entryDefinitionsReference)); for (String name : definitionNames) { pw.println("Name: " + name); pw.println("Content-Type: " + org.eclipse.winery.common.constants.MimeTypes.MIMETYPE_TOSCA_DEFINITIONS); pw.println(); } // Setting other files, mainly files belonging to artifacts for (RepositoryFileReference ref : refMap.keySet()) { String archivePath = refMap.get(ref); pw.println("Name: " + archivePath); String mimeType; if (ref instanceof DummyRepositoryFileReferenceForGeneratedXSD) { mimeType = MimeTypes.MIMETYPE_XSD; } else { mimeType = Repository.INSTANCE.getMimeType(ref); } pw.println("Content-Type: " + mimeType); pw.println(); } pw.flush(); out.closeArchiveEntry(); }
From source file:org.eclipse.winery.repository.export.ZipExporter.java
private String addManiYamlfest(TOSCAComponentId id, ArrayList<DefinitionResultInfo> defResultList, Map<RepositoryFileReference, String> refMap, ArchiveOutputStream out, TOSCAExportUtil exporter) throws IOException { if (defResultList.size() == 0) { return ""; }/*from w ww . jav a2 s . c o m*/ String content = getToscaMetaContent(defResultList, refMap, exporter); out.putArchiveEntry(new ZipArchiveEntry("TOSCA-Metadata/TOSCA.meta")); PrintWriter pw = new PrintWriter(out); pw.println(content); pw.flush(); out.closeArchiveEntry(); return MD5Util.md5(content); }
From source file:org.eclipse.winery.repository.ext.export.custom.ExportFileGenerator.java
/** * //from w w w . ja v a2 s.c o m * @param zos zip outputStream * @param fileName * @throws IOException */ public void createEntry(ArchiveOutputStream zos, String fileName) throws IOException { zos.putArchiveEntry(new ZipArchiveEntry(fileName)); }
From source file:org.fabrician.maven.plugins.CompressUtils.java
public static void copyZipToArchiveOutputStream(File zipSrc, FilenamePatternFilter filter, ArchiveOutputStream out, String alternateBaseDir) throws IOException { ZipFile zip = new ZipFile(zipSrc); for (Enumeration<ZipArchiveEntry> zipEnum = zip.getEntries(); zipEnum.hasMoreElements();) { ZipArchiveEntry source = zipEnum.nextElement(); if (filter != null && !filter.accept(source.getName())) { System.out.println("Excluding " + source.getName()); continue; }/* www .j a va 2 s . c o m*/ InputStream in = null; try { in = zip.getInputStream(source); out.putArchiveEntry(createArchiveEntry(source, out, alternateBaseDir)); IOUtils.copy(in, out); out.closeArchiveEntry(); } finally { close(in); } } }
From source file:org.fabrician.maven.plugins.CompressUtils.java
public static void copyTargzToArchiveOutputStream(File targzSrc, FilenamePatternFilter filter, ArchiveOutputStream out, String alternateBaseDir) throws IOException { FileInputStream fin = null;//w w w .jav a 2s.co m CompressorInputStream zipIn = null; TarArchiveInputStream tarIn = null; try { fin = new FileInputStream(targzSrc); zipIn = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.GZIP, fin); tarIn = new TarArchiveInputStream(zipIn); TarArchiveEntry entry = tarIn.getNextTarEntry(); while (entry != null) { if (filter != null && !filter.accept(entry.getName())) { System.out.println("Excluding " + entry.getName()); } else { out.putArchiveEntry(createArchiveEntry(entry, out, alternateBaseDir)); IOUtils.copy(tarIn, out); out.closeArchiveEntry(); } entry = tarIn.getNextTarEntry(); } } catch (Exception e) { throw new IOException(e); } finally { close(zipIn); close(tarIn); close(fin); } }
From source file:org.fabrician.maven.plugins.CompressUtils.java
/** * This attempts to mimic the filtering in the maven-assembly-plugin at a basic level. It wasn't clear how to use the archivers directly * in that plugin.//from w w w. ja va 2 s. c o m * Supports ${x} only. */ public static void copyFilteredDirToArchiveOutputStream(File baseDir, Properties replacements, ArchiveOutputStream out) throws IOException { File[] files = baseDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { continue; } String contents = transform(file, replacements); ByteArrayInputStream in = new ByteArrayInputStream(contents.getBytes()); ArchiveEntry entry = null; if (out instanceof TarArchiveOutputStream) { entry = new TarArchiveEntry(file.getName()); ((TarArchiveEntry) entry).setSize(contents.getBytes().length); ((TarArchiveEntry) entry).setModTime(file.lastModified()); } else { entry = new ZipArchiveEntry(file.getName()); ((ZipArchiveEntry) entry).setSize(contents.getBytes().length); ((ZipArchiveEntry) entry).setTime(file.lastModified()); } out.putArchiveEntry(entry); IOUtils.copy(in, out); out.closeArchiveEntry(); } } }