throw new ZipToSrampArchiveException(e.getMessage(),e); } finally { IOUtils.closeQuietly(resourceInputStream);
/** * Constructor. * @param jar * @throws ZipToSrampArchiveException */ public ZipToSrampArchive(File jar) throws ZipToSrampArchiveException { this.originalJar = jar; this.shouldDeleteOriginalJar = false; this.jarWorkDir = null; try { jarWorkDir = createJarWorkDir(); ArchiveUtils.unpackToWorkDir(this.originalJar, this.jarWorkDir); context = new ZipToSrampArchiveContext(this.jarWorkDir); } catch (IOException e) { if (this.jarWorkDir != null) { try { FileUtils.deleteDirectory(this.jarWorkDir); } catch (IOException e1) { } } throw new ZipToSrampArchiveException(e); } }
/** * Constructor from JAR input stream. Note, this will consume and close the given {@link InputStream}. * @param jarStream * @throws ZipToSrampArchiveException */ public ZipToSrampArchive(InputStream jarStream) throws ZipToSrampArchiveException { this.originalJar = null; this.shouldDeleteOriginalJar = true; this.jarWorkDir = null; try { this.originalJar = File.createTempFile("j2sramp", ".jar"); //$NON-NLS-1$ //$NON-NLS-2$ copyJarStream(jarStream, this.originalJar); jarWorkDir = createJarWorkDir(); ArchiveUtils.unpackToWorkDir(this.originalJar, this.jarWorkDir); context = new ZipToSrampArchiveContext(this.jarWorkDir); } catch (IOException e) { if (this.jarWorkDir != null) { try { FileUtils.deleteDirectory(this.jarWorkDir); } catch (IOException e1) { } } if (this.originalJar != null && this.originalJar.exists()) { this.originalJar.delete(); } throw new ZipToSrampArchiveException(e); } }
/** * Creates an S-RAMP archive from this JAR. * @return an S-RAMP archive * @throws ZipToSrampArchiveException */ public SrampArchive createSrampArchive() throws ZipToSrampArchiveException { this.artifactFilter.setContext(this.context); this.metaDataFactory.setContext(this.context); DiscoveredArtifacts discoveredArtifacts = discoverArtifacts(); discoveredArtifacts.index(jarWorkDir); generateMetaData(discoveredArtifacts); try { SrampArchive archive = new SrampArchive(); for (DiscoveredArtifact artifact : discoveredArtifacts) { String path = artifact.getArchivePath(); archive.addEntry(path, artifact.getMetaData(), artifact.getContent()); } return archive; } catch (Exception e) { throw new ZipToSrampArchiveException(e); } }