/** * Adds an entry to the S-RAMP archive. This method will close the content * {@link InputStream}. * @param path the path in the archive (usually just the name of the artifact) * @param metaData the artifact meta-data * @param content the entry content (or null if a meta-data only entry) * @throws SrampArchiveException */ public void addEntry(String path, BaseArtifactType metaData, InputStream content) throws SrampArchiveException { if (path == null) throw new SrampArchiveException(Messages.i18n.format("INVALID_ENTRY_PATH")); //$NON-NLS-1$ if (metaData == null) throw new SrampArchiveException(Messages.i18n.format("MISSING_META_DATA")); //$NON-NLS-1$ File metaDataFile = new File(this.workDir, path + ".atom"); //$NON-NLS-1$ File contentFile = new File(this.workDir, path); if (metaDataFile.exists()) throw new SrampArchiveException(Messages.i18n.format("ARCHIVE_ALREADY_EXISTS")); //$NON-NLS-1$ // Create any required parent directories metaDataFile.getParentFile().mkdirs(); if (content != null) writeContent(contentFile, content); try { SrampArchiveJaxbUtils.writeMetaData(metaDataFile, metaData); } catch (JAXBException e) { throw new SrampArchiveException(e); } }
/** * 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); } } }