class ComponentResourceImpl implements ComponentResource {

    @Override
    public StreamingOutput getDependency(final String id) {
        final ComponentFamilyMeta.BaseMeta<?> component = componentDao.findById(id);
        final Supplier<InputStream> streamProvider;
        if (component != null) { // local dep
            final Path file = componentManagerService
                    .manager()
                    .findPlugin(component.getParent().getPlugin())
                    .orElseThrow(() -> new WebApplicationException(Response
                            .status(Response.Status.NOT_FOUND)
                            .type(APPLICATION_JSON_TYPE)
                            .entity(new ErrorPayload(PLUGIN_MISSING, "No plugin matching the id: " + id))
                            .build()))
                    .getContainerFile()
                    .orElseThrow(() -> new WebApplicationException(Response
                            .status(Response.Status.NOT_FOUND)
                            .type(APPLICATION_JSON_TYPE)
                            .entity(new ErrorPayload(PLUGIN_MISSING, "No dependency matching the id: " + id))
                            .build()));
            if (!Files.exists(file)) {
                return onMissingJar(id);
            }
            streamProvider = () -> {
                try {
                    return Files.newInputStream(file);
                } catch (final IOException e) {
                    throw new IllegalStateException(e);
                }
            };
        } else { // just try to resolve it locally, note we would need to ensure some security here
            final Artifact artifact = Artifact.from(id);
            if (virtualDependenciesService.isVirtual(id)) {
                streamProvider = virtualDependenciesService.retrieveArtifact(artifact);
                if (streamProvider == null) {
                    return onMissingJar(id);
                }
            } else {
                final Path file = componentManagerService.manager().getContainer().resolve(artifact.toPath());
                if (!Files.exists(file)) {
                    return onMissingJar(id);
                }
                streamProvider = () -> {
                    try {
                        return Files.newInputStream(file);
                    } catch (final IOException e) {
                        throw new IllegalStateException(e);
                    }
                };
            }
        }
        return output -> {
            final byte[] buffer = new byte[40960]; // 5k
            try (final InputStream stream = new BufferedInputStream(streamProvider.get(), buffer.length)) {
                int count;
                while ((count = stream.read(buffer)) >= 0) {
                    if (count == 0) {
                        continue;
                    }
                    output.write(buffer, 0, count);
                }
            }
        };
    }

}