/** * Utility method for creating an {@link IArchiveResource} representing a file entry for the * passed {@link IPath}. * * @param path * @return */ protected IArchiveResource createFile(IPath archiveRelativePath) { verifyRelative(archiveRelativePath); IArchiveResource aFile = null; aFile = new ArchiveResourceImpl(); aFile.setPath(archiveRelativePath); aFile.setType(IArchiveResource.FILE_TYPE); aFile.setArchive(getArchive()); return aFile; }
/** * Utility method for creating an empty {@link IArchiveResource} manfiest file. * * @param manifestPath * @return */ protected IArchiveResource createManifest(IPath manifestPath) { verifyRelative(manifestPath); IArchiveResource manifest = null; manifest = new ArchiveResourceImpl() { @Override public InputStream getInputStream() throws FileNotFoundException, IOException { String manifestContents = "Manifest-Version: 1.0\r\n\r\n"; // $NON-NLS-1$ return new BufferedInputStream(new ByteArrayInputStream(manifestContents.getBytes())); } }; manifest.setPath(manifestPath); manifest.setType(IArchiveResource.FILE_TYPE); manifest.setArchive(getArchive()); return manifest; }
/** Default implementation; subclasses should override as necessary. */ public InputStream getInputStream(IArchiveResource archiveResource) throws IOException, FileNotFoundException { if (archiveResource.getType() == IArchive.ARCHIVE_TYPE) { IArchive thisArchive = (IArchive) archiveResource; ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); IArchiveSaveAdapter saveAdapter = new ZipStreamArchiveSaveAdapterImpl(byteOut); ArchiveOptions archiveOptions = new ArchiveOptions(); archiveOptions.setOption(ArchiveOptions.SAVE_ADAPTER, saveAdapter); try { IArchiveFactory.INSTANCE.saveArchive( thisArchive, archiveOptions, new NullProgressMonitor()); } catch (ArchiveSaveFailureException e) { throw new IOException( "Unable to save nested Archive " + archiveResource.getPath() + " nested exception = " + e.getMessage()); // $NON-NLS-1$//$NON-NLS-2$ } return new ByteArrayInputStream(byteOut.toByteArray()); } return null; }