Refine search
Map<ArchivePath, Node> archiveContents = archive.getContent(); for (Map.Entry<ArchivePath, Node> entry : archiveContents.entrySet()) { ArchivePath path = entry.getKey(); Node n = entry.getValue(); Path f = subpath(deployDir, path.get()); if (n.getAsset() == null) { Files.copy(n.getAsset().openStream(), f, StandardCopyOption.REPLACE_EXISTING); String p = n.getPath().get(); if (callback != null) { callback.accept(p);
private Manifest getBundleManifest(Archive<?> archive) { try { Node node = archive.get(JarFile.MANIFEST_NAME); if (node == null) return null; Manifest manifest = new Manifest(node.getAsset().openStream()); return manifest; } catch (Exception ex) { return null; } }
private void index(Archive<?> archive, List<IndexView> indexes) throws IOException { LOGGER.debugv("Indexing archive: {0}", archive.getName()); Node indexNode = archive.get(ArchivePaths.create(INDEX_LOCATION)); if (indexNode != null) { try (InputStream indexStream = indexNode.getAsset().openStream()) { LOGGER.debugv("Loading attached index from archive: {0}", archive.getName()); indexes.add(new IndexReader(indexStream).read()); for (Map.Entry<ArchivePath, Node> entry : archive.getContent(this::isClass).entrySet()) { try (InputStream contentStream = entry.getValue().getAsset().openStream()) { LOGGER.debugv("Indexing asset: {0} from archive: {1}", entry.getKey().get(), archive.getName()); indexer.index(contentStream); } catch (IOException indexerIOException) { LOGGER.warnv(indexerIOException, "Failed parsing: {0} from archive: {1}", entry.getKey().get(), archive.getName()); for (Map.Entry<ArchivePath, Node> entry : archive.getContent(a -> a.get().endsWith(JAR_SUFFIX)).entrySet()) { if (entry.getValue().getAsset() instanceof ArchiveAsset) { ArchiveAsset archiveAsset = (ArchiveAsset) entry.getValue().getAsset(); index(archiveAsset.getArchive(), indexes); } else { try (InputStream contentStream = entry.getValue().getAsset().openStream()) { JARArchive jarArchive = ShrinkWrap.create(JARArchive.class, entry.getKey().get()).as(ZipImporter.class).importFrom(contentStream) .as(JARArchive.class);
Map<ArchivePath, Node> c = deployment.getContent(); try { for (Map.Entry<ArchivePath, Node> each : c.entrySet()) { if (each.getKey().get().endsWith(CLASS_SUFFIX)) { indexer.index(each.getValue().getAsset().openStream()); Map<ArchivePath, Node> ctx = deployment.getContent(); for (Map.Entry<ArchivePath, Node> each : ctx.entrySet()) { System.err.println(each.getKey() + " // " + each.getValue()); final File out = new File(deployment.getName()); System.err.println("Exporting deployment to " + out.getAbsolutePath()); deployment.as(ZipExporter.class).exportTo(out, true);
Assert.assertFalse("Should have imported something", importedArchive.getContent().isEmpty()); Assert.assertTrue("Importer should have imported " + entryName.get() + " from " + originalSource, importedArchive.contains(entryName)); final Node node = importedArchive.get(entryName); byte[] importedContent = IOUtil.asByteArray(node.getAsset().openStream());
protected List<Properties> extractPomProperties(final Node node) { final List<Properties> properties = new ArrayList<>(); try (final InputStream in = node.getAsset().openStream()) { ShrinkWrap.create(ZipImporter.class) .importFrom(in) .as(JavaArchive.class) .getContent(p -> POM_PROPERTIES.matcher(p.get()).matches()) .values() .forEach(propNode -> { final Properties props = new Properties(); try (final InputStream in2 = propNode.getAsset().openStream()) { props.load(in2); } catch (IOException e) { throw new RuntimeException(e); } properties.add(props); }); } catch (IOException e) { throw new RuntimeException(e); } return properties; }
assertTrue(tmp.delete()); war.as(ZipExporter.class).exportTo(tmp); final byte[] bytes = Utils.readAsBytes(jar.get("foo/A.class").getAsset().openStream()); return new ClassLoader(Thread.currentThread().getContextClassLoader()) { Class<?> aClass = null;
@Test public void writeWithAppendOption() throws IOException { final String initialContent = "initial content"; final String appendContent = " - appended contents"; final String pathName = "content"; final Path path = fs.getPath(pathName); // Add the first initial content to the archive final Archive<?> archive = this.getArchive(); archive.add(new StringAsset(initialContent), pathName); // Write in append mode Files.write(path, appendContent.getBytes("UTF-8"), StandardOpenOption.APPEND); final String newContents = new BufferedReader(new InputStreamReader(archive.get(pathName).getAsset() .openStream())).readLine(); Assert.assertEquals("New contents was not appended as expected", initialContent + appendContent, newContents); }
if (archive.contains(channel.getName())) { final InputStream in = archive.get(archivePath).getAsset().openStream(); this.copy(in, channel); in.close(); archive.delete(archivePath); archive.add(channel); } else { throw new FileAlreadyExistsException(archivePath.get()); final Asset asset = node.getAsset(); if (asset == null) { throw new IllegalArgumentException("Cannot open a new channel to a path with existing directory: " + archivePath.get()); final InputStream in = asset.openStream(); final SeekableByteChannel outChannel = new SeekableInMemoryByteChannel(); this.copy(in, outChannel);
Asset asset = content.getAsset(); if (asset == null) { return null; return ArchiveAsset.class.cast(asset).getArchive().as(type); stream = asset.openStream(); X archive = ShrinkWrap.create(formatBinding.getImporter(), path.get()).importFrom(stream).as(type); delete(path); add(new ArchiveAsset(archive, formatBinding.getExporter()), path);
@Override public void undeploy(Archive<?> archive) throws DeploymentException { try { Manifest manifest = new Manifest(archive.get("/META-INF/MANIFEST.MF").getAsset().openStream()); OSGiMetaData metadata = OSGiMetaDataBuilder.load(manifest); undeploy(metadata.getBundleSymbolicName()); } catch (IOException e) { throw new DeploymentException("Cannot undeploy: " + archive.getName(), e); } }
@Override public InputStream getInputStream() throws IOException { ArchivePath path = convertToArchivePath(u); Node node = archive.get(prefix + path.get()); if (node == null && !prefix.isEmpty()) { // WEB-INF/lib/x.jar!* node = archive.get(path); } // SHRINKWRAP-308 if (node == null) { throw new FileNotFoundException("Requested path: " + path + " does not exist in " + archive.toString()); } Asset asset = node.getAsset(); if (asset == null) { return null; } InputStream input = asset.openStream(); synchronized (this) { openedStreams.add(input); } return input; }
public static WebArchive createDeployment(String packageName) throws IOException { WebArchive war = createPortletDeployment(packageName); Node node = war.get("WEB-INF/portlet.xml"); ArchivePath path = node.getPath(); String s = Tools.read(node.getAsset().openStream(), Tools.UTF_8); s = s.replace("<portlet-info>", "<resource-bundle>bundle</resource-bundle>" + "<portlet-info>"); war.delete(path); war.add(new StringAsset(s), path); war.addAsResource(new StringAsset("abc=def"), "bundle_fr_FR.properties"); return war; }
@Override public Manifest getManifest() throws IOException { ArchivePath manifestPath = ArchivePaths.create("META-INF/MANIFEST.MF"); final Archive<?> archive = this.getArchive(); if (archive.contains(manifestPath)) { return new Manifest(archive.get(manifestPath).getAsset().openStream()); } return null; }
private static boolean hasApplicationPathAnnotation(ArchivePath path, Asset asset) { if (asset == null) { return false; } if (! path.get().endsWith(".class" ) ) { return false; } try (InputStream in = asset.openStream() ) { ClassReader reader = new ClassReader(in); AnnotationSeekingClassVisitor visitor = new AnnotationSeekingClassVisitor(); reader.accept(visitor, 0 ); return visitor.isFound(); } catch (FileNotFoundException e) { } catch (IOException e) { } return false; }
@Override public InputStream get() throws IOException { return asset.openStream(); } }
private Manifest getBundleManifest(Archive<?> archive) { try { Node node = archive.get(JarFile.MANIFEST_NAME); if (node == null) return null; Manifest manifest = new Manifest(node.getAsset().openStream()); return manifest; } catch (Exception ex) { return null; } }
private void index(Archive<?> archive, List<IndexView> indexes) throws IOException { LOGGER.debugv("Indexing archive: {0}", archive.getName()); Node indexNode = archive.get(ArchivePaths.create(INDEX_LOCATION)); if (indexNode != null) { try (InputStream indexStream = indexNode.getAsset().openStream()) { LOGGER.debugv("Loading attached index from archive: {0}", archive.getName()); indexes.add(new IndexReader(indexStream).read()); for (Map.Entry<ArchivePath, Node> entry : archive.getContent(this::isClass).entrySet()) { try (InputStream contentStream = entry.getValue().getAsset().openStream()) { LOGGER.debugv("Indexing asset: {0} from archive: {1}", entry.getKey().get(), archive.getName()); indexer.index(contentStream); } catch (IOException indexerIOException) { LOGGER.warnv(indexerIOException, "Failed parsing: {0} from archive: {1}", entry.getKey().get(), archive.getName()); for (Map.Entry<ArchivePath, Node> entry : archive.getContent(a -> a.get().endsWith(JAR_SUFFIX)).entrySet()) { if (entry.getValue().getAsset() instanceof ArchiveAsset) { ArchiveAsset archiveAsset = (ArchiveAsset) entry.getValue().getAsset(); index(archiveAsset.getArchive(), indexes); } else { try (InputStream contentStream = entry.getValue().getAsset().openStream()) { JARArchive jarArchive = ShrinkWrap.create(JARArchive.class, entry.getKey().get()).as(ZipImporter.class).importFrom(contentStream) .as(JARArchive.class);
Assert.assertFalse("Should have imported something", importedArchive.getContent().isEmpty()); Assert.assertTrue("Importer should have imported " + entryName.get() + " from " + originalSource, importedArchive.contains(entryName)); final Node node = importedArchive.get(entryName); byte[] importedContent = IOUtil.asByteArray(node.getAsset().openStream());
protected void processNode(ArchivePath path, Node node) { final String assetFilePath = path.get(); if (node != null && node.getAsset() instanceof ArchiveAsset) { ArchiveAsset nesteArchiveAsset = ArchiveAsset.class.cast(node.getAsset()); processArchiveAsset(assetParent, nesteArchiveAsset); return; final boolean isDirectory = (node.getAsset() == null); if (isDirectory) { try { if (log.isLoggable(Level.FINE)) { log.fine("Writing asset " + path.get() + " to " + assetFile.getAbsolutePath()); final InputStream assetInputStream = node.getAsset().openStream(); final FileOutputStream assetFileOutputStream = new FileOutputStream(assetFile); final BufferedOutputStream assetBufferedOutputStream = new BufferedOutputStream(