public Archive merge(Archive archive) { Map<String, File> entriesToMerge = archive.getEntries(); for (Entry<String, File> entry : entriesToMerge.entrySet()) { File file = entry.getValue(); if (file != null && !file.isDirectory()) { try { addEntry(entry.getKey(), FileUtils.readFile(file)); } catch (IOException e) { throw new IllegalStateException("Unexpected error reading Archive file '" + file.getAbsolutePath() + "'.", e); } } else { addEntry(entry.getKey(), (byte[]) null); } } return this; }
public Archive merge(Archive archive) { Map<String, File> entriesToMerge = archive.getEntries(); for (Entry<String, File> entry : entriesToMerge.entrySet()) { File file = entry.getValue(); if (file != null && !file.isDirectory()) { try { addEntry(entry.getKey(), FileUtils.readFile(file)); } catch (IOException e) { throw new IllegalStateException("Unexpected error reading Archive file '" + file.getAbsolutePath() + "'.", e); } } else { addEntry(entry.getKey(), (byte[]) null); } } return this; }
public Archive merge(Archive archive) { Map<String, File> entriesToMerge = archive.getEntries(); for (Entry<String, File> entry : entriesToMerge.entrySet()) { File file = entry.getValue(); if (file != null && !file.isDirectory()) { try { addEntry(entry.getKey(), FileUtils.readFile(file)); } catch (IOException e) { throw new IllegalStateException("Unexpected error reading Archive file '" + file.getAbsolutePath() + "'.", e); } } else { addEntry(entry.getKey(), (byte[]) null); } } return this; }
private String saveSchema(Archive archive, String entryPath, Resource resource, String ns, String pluginID) { StringBuilder result = new StringBuilder(); ByteArrayOutputStream out = new ByteArrayOutputStream(); log.info("Saving XML Schema " + ns); try { resource.save(out, null); if (archive.getEntries().containsKey(entryPath)) { throw new RuntimeException("Duplicate entry " + entryPath); } archive.addEntry(entryPath, out.toByteArray()); result.append("\t<uri name=\""); result.append(ns); result.append("\" uri=\"platform:/fragment/" + pluginID + "/"); result.append(entryPath); result.append("\"/>\n"); } catch (Exception e) { log.error("Failed to save XML Schema " + ns, e); } return result.toString(); }
/** * Add the specified classpath resource as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param resource The classpath resource. * @return This archive instance. * @throws java.io.IOException Failed to read resource from classpath. */ public Archive addClasspathResourceEntry(String path, String resource) throws IOException { AssertArgument.isNotNull(path, "path"); AssertArgument.isNotNull(resource, "resource"); InputStream resourceStream = getClass().getResourceAsStream(resource); if(resourceStream == null) { throw new IOException("Classpath resource '" + resource + "' no found."); } else { addEntry(path, resourceStream); } return this; }
/** * Add the specified classpath resource as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param resource The classpath resource. * @return This archive instance. * @throws java.io.IOException Failed to read resource from classpath. */ public Archive addClasspathResourceEntry(String path, String resource) throws IOException { AssertArgument.isNotNull(path, "path"); AssertArgument.isNotNull(resource, "resource"); InputStream resourceStream = getClass().getResourceAsStream(resource); if(resourceStream == null) { throw new IOException("Classpath resource '" + resource + "' no found."); } else { addEntry(path, resourceStream); } return this; }
/** * Add the specified classpath resource as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param resource The classpath resource. * @return This archive instance. * @throws java.io.IOException Failed to read resource from classpath. */ public Archive addClasspathResourceEntry(String path, String resource) throws IOException { AssertArgument.isNotNull(path, "path"); AssertArgument.isNotNull(resource, "resource"); InputStream resourceStream = getClass().getResourceAsStream(resource); if(resourceStream == null) { throw new IOException("Classpath resource '" + resource + "' no found."); } else { addEntry(path, resourceStream); } return this; }
/** * Add the supplied character data as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param data The data. * @return This archive instance. */ public Archive addEntry(String path, String data) { AssertArgument.isNotNullAndNotEmpty(path, "path"); AssertArgument.isNotNull(data, "data"); try { addEntry(trimLeadingSlash(path.trim()), data.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unexpected UnsupportedEncodingException exception for encoding 'UTF-8' when writing Archive entry from a StringBuilder instance.", e); } return this; }
/** * Add the supplied character data as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param data The data. * @return This archive instance. */ public Archive addEntry(String path, String data) { AssertArgument.isNotNullAndNotEmpty(path, "path"); AssertArgument.isNotNull(data, "data"); try { addEntry(trimLeadingSlash(path.trim()), data.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unexpected UnsupportedEncodingException exception for encoding 'UTF-8' when writing Archive entry from a StringBuilder instance.", e); } return this; }
/** * Add the supplied character data as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param data The data. * @return This archive instance. */ public Archive addEntry(String path, String data) { AssertArgument.isNotNullAndNotEmpty(path, "path"); AssertArgument.isNotNull(data, "data"); try { addEntry(trimLeadingSlash(path.trim()), data.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unexpected UnsupportedEncodingException exception for encoding 'UTF-8' when writing Archive entry from a StringBuilder instance.", e); } return this; }
private static void addModel(Edimap model, String pathPrefix, StringBuilder modelListBuilder, StringWriter messageEntryWriter, Archive archive) throws IOException { Description modelDesc = model.getDescription(); String messageEntryPath = pathPrefix + "/" + modelDesc.getName() + ".xml"; // Generate the mapping model for this message... messageEntryWriter.getBuffer().setLength(0); model.write(messageEntryWriter); // Add the generated mapping model to the archive... archive.addEntry(messageEntryPath, messageEntryWriter.toString()); // Add this messages archive entry to the mapping model list file... modelListBuilder.append("/" + messageEntryPath); modelListBuilder.append("!" + modelDesc.getName()); modelListBuilder.append("!" + modelDesc.getVersion()); modelListBuilder.append("!" + modelDesc.getNamespace()); modelListBuilder.append("\n"); }
archive.addEntry(EDIUtils.EDI_MAPPING_MODEL_ZIP_LIST_FILE, modelListBuilder.toString()); archive.addEntry(EDIUtils.EDI_MAPPING_MODEL_URN, urn); interchangeProperties.store(propertiesOutStream, "UN/EDIFACT Interchange Properties"); propertiesOutStream.flush(); archive.addEntry(EDIUtils.EDI_MAPPING_MODEL_INTERCHANGE_PROPERTIES_FILE, propertiesOutStream.toByteArray()); } finally { propertiesOutStream.close();
/** * Add the supplied data as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param data The data. * @return This archive instance. * @throws IOException Error reading from data stream. */ public Archive addEntry(String path, InputStream data) throws IOException { AssertArgument.isNotNullAndNotEmpty(path, "path"); AssertArgument.isNotNull(data, "data"); try { byte[] dataBytes = StreamUtils.readStream(data); addEntry(trimLeadingSlash(path.trim()), dataBytes); } finally { try { data.close(); } catch (IOException e) { logger.warn("Unable to close input stream for archive entry '" + path + "'."); } } return this; }
/** * Add the supplied data as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param data The data. * @return This archive instance. * @throws IOException Error reading from data stream. */ public Archive addEntry(String path, InputStream data) throws IOException { AssertArgument.isNotNullAndNotEmpty(path, "path"); AssertArgument.isNotNull(data, "data"); try { byte[] dataBytes = StreamUtils.readStream(data); addEntry(trimLeadingSlash(path.trim()), dataBytes); } finally { try { data.close(); } catch (IOException e) { logger.warn("Unable to close input stream for archive entry '" + path + "'."); } } return this; }
public Archive createArchive(Set<EPackage> packages, String pluginID, String pathPrefix) throws IOException { String qualifier = qualifierFormat.format(Calendar.getInstance() .getTime()); Archive archive = new Archive(pluginID + "_1.0.0.v" + qualifier + ".jar"); StringBuilder pluginBuilder = new StringBuilder( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<?eclipse version=\"3.0\"?>\n" + "<plugin>\n"); StringBuilder xmlExtension = new StringBuilder( "\t<extension point=\"org.eclipse.wst.xml.core.catalogContributions\"><catalogContribution>\n"); for (EPackage pkg : packages) { ResourceSet rs = createResourceSet(); Resource resource = addSchemaResource(rs, pkg); EObject obj = resource.getContents().get(0); String fileName = resource.getURI().lastSegment(); String ecoreEntryPath = pathPrefix + "/" + fileName; xmlExtension.append(saveSchema(archive, ecoreEntryPath, resource, ((XSDSchema) obj).getTargetNamespace(), pluginID)); // Save memory System.gc(); } xmlExtension.append("\t</catalogContribution></extension>\n"); pluginBuilder.append(xmlExtension); pluginBuilder.append("</plugin>"); archive.addEntry(FRAGMENT_XML_ENTRY, pluginBuilder.toString()); return archive; }
/** * Add the supplied data as an entry in the deployment. * * @param path The target path of the entry when added to the archive. * @param data The data. * @return This archive instance. * @throws IOException Error reading from data stream. */ public Archive addEntry(String path, InputStream data) throws IOException { AssertArgument.isNotNullAndNotEmpty(path, "path"); AssertArgument.isNotNull(data, "data"); try { byte[] dataBytes = StreamUtils.readStream(data); addEntry(trimLeadingSlash(path.trim()), dataBytes); } finally { try { data.close(); } catch (IOException e) { logger.warn("Unable to close input stream for archive entry '" + path + "'."); } } return this; }