@Override public InputStream getContent() { try { ContentCapability c = ResourceUtils.getContentCapability(this); URI url = c.url(); return url.toURL() .openStream(); } catch (Exception e) { throw new RuntimeException(e); } } }
public static Map<URI, String> getLocations(Resource resource) { return capabilityStream(resource, ContentNamespace.CONTENT_NAMESPACE, ContentCapability.class) .filter(c -> Objects.nonNull(c.url())) // We can't use Collectors.toMap since we must handle null // ContentCapability::osgi_content values. // .collect(toMap(ContentCapability::url, // ContentCapability::osgi_content)); .collect(Collector.of(HashMap::new, (m, c) -> m.put(c.url(), c.osgi_content()), (m1, m2) -> { m1.putAll(m2); return m1; })); }
public static Map<URI, String> getLocations(Resource resource) { return capabilityStream(resource, ContentNamespace.CONTENT_NAMESPACE, ContentCapability.class) .filter(c -> Objects.nonNull(c.url())) // We can't use Collectors.toMap since we must handle null // ContentCapability::osgi_content values. // .collect(toMap(ContentCapability::url, // ContentCapability::osgi_content)); .collect(Collector.of(HashMap::new, (m, c) -> m.put(c.url(), c.osgi_content()), (m1, m2) -> { m1.putAll(m2); return m1; })); }
File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception { Resource resource = getBridge().get(bsn, version); if (resource == null) return null; ContentCapability contentCapability = ResourceUtils.getContentCapability(resource); if (contentCapability == null) return null; URI url = contentCapability.url(); final File source = client.getCacheFileFor(url); final File link = new File(location, bsn + "-" + version + ".jar"); IO.createSymbolicLinkOrCopy(link, source); Promise<File> go = client.build() .useCache(MAX_STALE) .async(url.toURL()) .map(file -> link); if (listeners.length == 0) return go.getValue(); new DownloadListenerPromise(reporter, name + ": get " + bsn + ";" + version + " " + url, go, listeners); return link; }
private Promise<File> get(final String bsn, final Version version) throws Exception { logger.debug("{}: get {} {}", getName(), bsn, version); Resource resource = getBridge().get(bsn, version); if (resource == null) { logger.debug("{}: resource not found {} {}", getName(), bsn, version); return null; } ContentCapability content = ResourceUtils.getContentCapability(resource); if (content == null) { logger.warn("{}: No content capability for {}", getName(), resource); return null; } URI uri = content.url(); if (uri == null) { logger.warn("{}: No content URI for {}", getName(), resource); return null; } logger.debug("{}: get returning {}", getName(), uri); return promiseFactory.resolved(new File(uri)); }
private Promise<File> get(final String bsn, final Version version) throws Exception { logger.debug("{}: get {} {}", getName(), bsn, version); Resource resource = getBridge().get(bsn, version); if (resource == null) { logger.debug("{}: resource not found {} {}", getName(), bsn, version); return null; } ContentCapability content = ResourceUtils.getContentCapability(resource); if (content == null) { logger.warn("{}: No content capability for {}", getName(), resource); return null; } URI uri = content.url(); if (uri == null) { logger.warn("{}: No content URI for {}", getName(), resource); return null; } logger.debug("{}: get returning {}", getName(), uri); return promiseFactory.resolved(new File(uri)); }
File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception { Resource resource = getBridge().get(bsn, version); if (resource == null) return null; ContentCapability contentCapability = ResourceUtils.getContentCapability(resource); if (contentCapability == null) return null; URI url = contentCapability.url(); final File source = client.getCacheFileFor(url); final File link = new File(location, bsn + "-" + version + ".jar"); IO.createSymbolicLinkOrCopy(link, source); Promise<File> go = client.build() .useCache(MAX_STALE) .async(url.toURL()) .map(file -> link); if (listeners.length == 0) return go.getValue(); new DownloadListenerPromise(reporter, name + ": get " + bsn + ";" + version + " " + url, go, listeners); return link; }
File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception { Resource resource = getBridge().get(bsn, version); if (resource == null) return null; ContentCapability contentCapability = ResourceUtils.getContentCapability(resource); if (contentCapability == null) return null; URI url = contentCapability.url(); final File source = client.getCacheFileFor(url); final File link = new File(location, bsn + "-" + version + ".jar"); IO.createSymbolicLinkOrCopy(link, source); Promise<File> go = client.build() .useCache(MAX_STALE) .async(url.toURL()) .map(file -> link); if (listeners.length == 0) return go.getValue(); new DownloadListenerPromise(reporter, name + ": get " + bsn + ";" + version + " " + url, go, listeners); return link; }
File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception { Resource resource = getBridge().get(bsn, version); if (resource == null) return null; ContentCapability contentCapability = ResourceUtils.getContentCapability(resource); if (contentCapability == null) return null; URI url = contentCapability.url(); final File source = client.getCacheFileFor(url); final File link = new File(location, bsn + "-" + version + ".jar"); IO.createSymbolicLinkOrCopy(link, source); Promise<File> go = client.build() .useCache(MAX_STALE) .async(url.toURL()) .map(file -> link); if (listeners.length == 0) return go.getValue(); new DownloadListenerPromise(reporter, name + ": get " + bsn + ";" + version + " " + url, go, listeners); return link; }
Promise<File> get(String bsn, Version version, File file) throws Exception { Resource resource = getBridge().get(bsn, version); if (resource == null) return null; ContentCapability content = ResourceUtils.getContentCapability(resource); if (content == null) { logger.warn("{}: No content capability for {}", name, resource); return null; } URI url = content.url(); if (url == null) { logger.warn("{}: No content URL for {}", name, resource); return null; } return client.build() .useCache(file, staleTime) .async(url); }
Promise<File> get(String bsn, Version version, File file) throws Exception { Resource resource = getBridge().get(bsn, version); if (resource == null) return null; ContentCapability content = ResourceUtils.getContentCapability(resource); if (content == null) { logger.warn("{}: No content capability for {}", name, resource); return null; } URI url = content.url(); if (url == null) { logger.warn("{}: No content URL for {}", name, resource); return null; } return client.build() .useCache(file, staleTime) .async(url); }
@Override public InputStream getContent() { try { ContentCapability c = ResourceUtils.getContentCapability(this); URI url = c.url(); return url.toURL() .openStream(); } catch (Exception e) { throw new RuntimeException(e); } } }