/** * Gets the content {@link InputStream} for the given S-RAMP archive entry. * @param entry the s-ramp archive entry * @return an {@link InputStream} over the artifact content or null if no content found (meta-data only) * @throws IOException */ public InputStream getInputStream(SrampArchiveEntry entry) throws IOException { File artifactPath = new File(this.workDir, entry.getPath()); if (artifactPath.exists()) return FileUtils.openInputStream(artifactPath); else return null; }
/** * Updates an existing entry in the S-RAMP archive. This method will close the content * {@link InputStream}. * @param entry the archive entry (or null if just udpating the content) * @param content the entry content (or null if just updating meta data) * @throws SrampArchiveException */ public void updateEntry(SrampArchiveEntry entry, InputStream content) throws SrampArchiveException { if (entry.getPath() == null) throw new SrampArchiveException(Messages.i18n.format("INVALID_ENTRY_PATH")); //$NON-NLS-1$ File contentFile = new File(this.workDir, entry.getPath()); File metaDataFile = new File(this.workDir, entry.getPath() + ".atom"); //$NON-NLS-1$ if (content != null) writeContent(contentFile, content); if (entry.getMetaData() != null) { try { SrampArchiveJaxbUtils.writeMetaData(metaDataFile, entry.getMetaData()); } catch (JAXBException e) { throw new SrampArchiveException(e); } } }
/** * Test method for {@link org.overlord.sramp.atom.archive.jar.ZipToSrampArchive.jar.JarToSrampArchive#createSrampArchive()}. */ @Test public void testCreateSrampArchive() throws Exception { InputStream resourceAsStream = ZipToSrampArchiveTest.class.getResourceAsStream("sample-webservice-0.0.1.jar"); //$NON-NLS-1$ ZipToSrampArchive j2sramp = null; SrampArchive archive = null; try { j2sramp = new ZipToSrampArchive(resourceAsStream){}; archive = j2sramp.createSrampArchive(); Assert.assertNotNull(archive); Collection<SrampArchiveEntry> entries = archive.getEntries(); Assert.assertEquals(2, entries.size()); Set<String> paths = new HashSet<String>(); for (SrampArchiveEntry entry : entries) { paths.add(entry.getPath()); } Assert.assertEquals(2, entries.size()); Assert.assertTrue(paths.contains("schema/teetime.xsd")); //$NON-NLS-1$ Assert.assertTrue(paths.contains("wsdl/teetime.wsdl")); //$NON-NLS-1$ } finally { ZipToSrampArchive.closeQuietly(j2sramp); SrampArchive.closeQuietly(archive); } }
Set<String> paths = new HashSet<String>(); for (SrampArchiveEntry entry : entries) { paths.add(entry.getPath());
/** * Asserts that the s-ramp archive was properly created. * @param archive * @throws SrampArchiveException */ private void doAllAssertions(SrampArchive archive) throws SrampArchiveException { Collection<SrampArchiveEntry> entries = archive.getEntries(); // Make sure all the entries we expect to be there are there. TreeSet<String> entryNames = new TreeSet<String>(); for (SrampArchiveEntry srampArchiveEntry : entries) { entryNames.add(srampArchiveEntry.getPath()); } StringBuilder buff = new StringBuilder(); for (String entryName : entryNames) { buff.append(entryName).append("\n"); //$NON-NLS-1$ } Assert.assertEquals(EXPECTED_ENTRIES, buff.toString()); // Now spot-check some representative entries. // Check the kmodule.xml SrampArchiveEntry entry = archive.getEntry("META-INF/kmodule.xml"); //$NON-NLS-1$ Assert.assertNotNull(entry); Assert.assertEquals("kmodule.xml", entry.getMetaData().getName()); //$NON-NLS-1$ Assert.assertEquals(BaseArtifactEnum.EXTENDED_DOCUMENT, entry.getMetaData().getArtifactType()); ExtendedDocument kieXmlDoc = (ExtendedDocument) entry.getMetaData(); Assert.assertEquals(KieJarModel.KieXmlDocument, kieXmlDoc.getExtendedType()); }
Assert.assertEquals(1, entries.size()); SrampArchiveEntry entry = entries.iterator().next(); Assert.assertEquals("simple-sramp-archive/sample.xsd", entry.getPath()); //$NON-NLS-1$ Assert.assertNotNull(entry.getMetaData()); Assert.assertEquals("d658b181-975c-42c5-ad5c-dc65cb9aa4a1", entry.getMetaData().getUuid()); //$NON-NLS-1$
entryNames.add(srampArchiveEntry.getPath());
Map<String, SrampArchiveEntry> entryMap = new HashMap<String, SrampArchiveEntry>(); for (SrampArchiveEntry entry : entries) entryMap.put(entry.getPath(), entry);