Java Code Examples for org.sonatype.nexus.repository.view.Content#openInputStream()
The following examples show how to use
org.sonatype.nexus.repository.view.Content#openInputStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrientMavenTestHelper.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override public void verifyHashesExistAndCorrect(final Repository repository, final String path) throws Exception { final MavenFacet mavenFacet = repository.facet(MavenFacet.class); final MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(path); UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier()); try { final Content content = mavenFacet.get(mavenPath); assertThat(content, notNullValue()); final Map<HashAlgorithm, HashCode> hashCodes = content.getAttributes().require(Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP); for (HashType hashType : HashType.values()) { final Content contentHash = mavenFacet.get(mavenPath.hash(hashType)); final String storageHash = hashCodes.get(hashType.getHashAlgorithm()).toString(); assertThat(storageHash, notNullValue()); try (InputStream is = contentHash.openInputStream()) { final String mavenHash = CharStreams.toString(new InputStreamReader(is, StandardCharsets.UTF_8)); assertThat(storageHash, equalTo(mavenHash)); } } } finally { UnitOfWork.end(); } }
Example 2
Source File: OrientNpmGroupFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
protected InputStream buildMergedPackageRootOnMissingBlob(final Map<Repository, Response> responses, final Context context, final MissingAssetBlobException e) throws IOException { if (log.isTraceEnabled()) { log.info("Missing blob {} containing cached metadata {}, deleting asset and triggering rebuild.", e.getBlobRef(), e.getAsset(), e); } else { log.info("Missing blob {} containing cached metadata {}, deleting asset and triggering rebuild.", e.getBlobRef(), e.getAsset().name()); } cleanupPackageRootAssetOnlyFromCache(e.getAsset()); Content content = buildMergedPackageRoot(responses, context); // it should never be null, but we are being kind and return an error stream. return nonNull(content) ? content.openInputStream() : errorInputStream("Unable to retrieve merged package root on recovery for missing blob"); }
Example 3
Source File: OrientPyPiProxyFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Using a cached index asset attempt to retrieve the link for a given package. */ private Optional<PyPiLink> getExistingPackageLink(final String packageName, final String filename) { Content index = getAsset(indexPath(packageName)); if (index == null) { return Optional.empty(); } String rootFilename = filename.endsWith(".asc") ? filename.substring(0, filename.length() - 4) : filename; try (InputStream in = index.openInputStream()) { return extractLinksFromIndex(in).stream().filter(link -> rootFilename.equals(link.getFile())) .findFirst(); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example 4
Source File: OrientPyPiProxyFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private Content putIndex(final String name, final Content content) throws IOException { String html; String path = indexPath(name); try (InputStream inputStream = content.openInputStream()) { html = IOUtils.toString(inputStream); if (!validateIndexLinks(name, extractLinksFromIndex(html))) { return null; } makeIndexLinksNexusPaths(name, inputStream); storeHtmlPage(content, html, INDEX, path); return rewriteIndex(name); } catch (Exception e) { throw new IOException(e); } }
Example 5
Source File: OrientPyPiGroupFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected AssetBlob updateAsset(final StorageTx tx, final Asset asset, final Content content) throws IOException { AttributesMap contentAttributes = Content.maintainLastModified(asset, content.getAttributes()); Content.applyToAsset(asset, contentAttributes); InputStream inputStream = content.openInputStream(); AssetBlob blob = tx.setBlob(asset, asset.name(), () -> inputStream, HASH_ALGORITHMS, null, ContentTypes.TEXT_HTML, true); tx.saveAsset(asset); return blob; }
Example 6
Source File: NpmFacetUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private static NestedAttributesMap readDistTagResponse(final Content content) { try (InputStream is = content.openInputStream()) { return NpmJsonUtils.parse(() -> is); } catch (IOException ignore) { //NOSONAR } return null; }
Example 7
Source File: OrientPyPiProxyFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private Content putRootIndex(final Content content) throws IOException { try (InputStream inputStream = content.openInputStream()) { List<PyPiLink> links = makeRootIndexRelative(inputStream); String indexPage = buildRootIndexPage(templateHelper, links); return storeHtmlPage(content, indexPage, ROOT_INDEX, INDEX_PATH_PREFIX); } }
Example 8
Source File: MavenIndexPublisher.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public InputStream read() throws IOException { Content content = mavenFacet.get(mavenPath); if (content != null) { return content.openInputStream(); } return null; }
Example 9
Source File: OrientMetadataRebuilder.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Returns the plugin prefix of a Maven plugin, by opening up the plugin JAR, and reading the Maven Plugin * Descriptor. If fails, falls back to mangle artifactId (ie. extract XXX from XXX-maven-plugin or * maven-XXX-plugin). */ private String getPluginPrefix(final MavenPath mavenPath) { // sanity checks: is artifact and extension is "jar", only possibility for maven plugins currently checkArgument(mavenPath.getCoordinates() != null); checkArgument(Objects.equals(mavenPath.getCoordinates().getExtension(), "jar")); String prefix = null; try { final Content jarFile = mavenFacet.get(mavenPath); if (jarFile != null) { try (ZipInputStream zip = new ZipInputStream(jarFile.openInputStream())) { ZipEntry entry; while ((entry = zip.getNextEntry()) != null) { if (!entry.isDirectory() && "META-INF/maven/plugin.xml".equals(entry.getName())) { final Xpp3Dom dom = parse(mavenPath, zip); prefix = getChildValue(dom, "goalPrefix", null); break; } zip.closeEntry(); } } } } catch (IOException e) { log.warn("Unable to read plugin.xml of {}", mavenPath, e); } if (prefix != null) { return prefix; } if ("maven-plugin-plugin".equals(mavenPath.getCoordinates().getArtifactId())) { return "plugin"; } else { return mavenPath.getCoordinates().getArtifactId().replaceAll("-?maven-?", "").replaceAll("-?plugin-?", ""); } }
Example 10
Source File: ConcurrentProxyTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
ConcurrentTask verifyValidGet(final Request request) { return () -> { try { Content content = underTest.get(new Context(repository, request)); try (InputStream in = content.openInputStream()) { assertThat(toByteArray(in), is(ASSET_CONTENT)); } } catch (IOException e) { fail("Unexpected " + e); } }; }
Example 11
Source File: TempContent.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private static Payload cachePayload(final Content remote) throws IOException { try (InputStream in = remote.openInputStream()) { return new BytesPayload(toByteArray(in), remote.getContentType()); } }