/** * Builds a packages.json file as a {@code Content} instance containing the actual JSON for the given providers. */ private Content buildPackagesJson(final Repository repository, final Set<String> names) throws IOException { Map<String, Object> packagesJson = new LinkedHashMap<>(); packagesJson.put(PROVIDERS_URL_KEY, repository.getUrl() + PACKAGE_JSON_PATH); packagesJson.put(PROVIDERS_KEY, names.stream() .collect(Collectors.toMap((each) -> each, (each) -> singletonMap(SHA256_KEY, null)))); return new Content(new StringPayload(mapper.writeValueAsString(packagesJson), ContentTypes.APPLICATION_JSON)); }
/** * Create {@link Content} out of HTTP response. */ protected Content createContent(final Context context, final HttpResponse response) { return new Content(new HttpEntityPayload(response, response.getEntity())); }
/** * Merges the metadata but doesn't cache it. Returns {@code null} if no usable response was in passed in map. * * @since 3.13 */ @Nullable public Content mergeWithoutCaching(final MavenPath mavenPath, final Map<Repository, Response> responses) throws IOException { return merge(mavenPath, responses, Function.identity(), (in, contentType) -> { // load bytes in memory to make content re-usable; metadata shouldn't be too large // (don't include cache-related attributes since this content has not been cached) return new Content(new BytesPayload(toByteArray(in), contentType)); }); }
return new Content(new StringPayload(mapper.writeValueAsString(singletonMap(PACKAGES_KEY, packages)), ContentTypes.APPLICATION_JSON));
/** * Convert an asset blob to {@link Content}. * * @return content of asset blob */ @Nonnull public static Content toContent(final Asset asset, final Blob blob) { Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, HASH_ALGORITHMS, content.getAttributes()); return content; }
return new Content(new StreamPayload( new InputStreamSupplier()
public Content getPublicKey() throws IOException, PGPException { PGPSecretKey signKey = readSecretKey(); PGPPublicKey publicKey = signKey.getPublicKey(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try (BCPGOutputStream os = new BCPGOutputStream(new ArmoredOutputStream(buffer))) { publicKey.encode(os); } return new Content(new BytesPayload(buffer.toByteArray(), AptMimeTypes.PUBLICKEY)); }
return new Content(new StringPayload(mapper.writeValueAsString(singletonMap(PACKAGES_KEY, packages)), ContentTypes.APPLICATION_JSON));
/** * Convert an asset blob to {@link Content}. * * @return content of asset blob */ public Content toContent(final Asset asset, final Blob blob) { Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, HASH_ALGORITHMS, content.getAttributes()); return content; } }
private Content toContent(final Asset asset, final Blob blob) { final Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, hashAlgorithms, content.getAttributes()); return content; } }
private Content toContent(final Asset asset, final Blob blob) { final String contentType = asset.contentType(); final Content content = new Content(new BlobPayload(blob, contentType)); Content.extractFromAsset(asset, HashType.ALGORITHMS, content.getAttributes()); return content; }
/** * Creates a {@link Content} out of passed in package metadata. */ @Nonnull static Content toContent(final Asset packageRootAsset, final NestedAttributesMap packageRoot) { Content content = new Content(new BytesPayload(NpmJsonUtils.bytes(packageRoot), ContentTypes.APPLICATION_JSON)); Content.extractFromAsset(packageRootAsset, HASH_ALGORITHMS, content.getAttributes()); content.getAttributes().set(NestedAttributesMap.class, packageRoot); return content; }
public static Content toContent(final Asset asset, final Blob blob) { final Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, hashAlgorithms, content.getAttributes()); return content; }
private Content toContent(final Asset asset, final Blob blob) { final Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, hashAlgorithms, content.getAttributes()); return content; } }
public static void addHashes(final MavenFacet mavenFacet, final MavenPath mavenPath, final Map<HashAlgorithm, HashCode> hashCodes, final DateTime now) throws IOException { for (HashType hashType : HashType.values()) { final HashCode hashCode = hashCodes.get(hashType.getHashAlgorithm()); if (hashCode != null) { final Content hashContent = new Content( new StringPayload(hashCode.toString(), Constants.CHECKSUM_CONTENT_TYPE)); hashContent.getAttributes().set(Content.CONTENT_LAST_MODIFIED, now); mavenFacet.put(mavenPath.hash(hashType), hashContent); } } }
hashCodes.put(entry.getKey(), entry.getValue().hash()); Content content = new Content(new StreamPayload( new InputStreamSupplier()
/** * Returns the tarball content. */ @Nullable static Content getTarballContent(final StorageTx tx, final Bucket bucket, final NpmPackageId packageId, final String tarballName) { Asset asset = findTarballAsset(tx, bucket, packageId, tarballName); if (asset == null) { return null; } Blob blob = tx.requireBlob(asset.requireBlobRef()); Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, HASH_ALGORITHMS, content.getAttributes()); return content; }
Content fetchedContent = new Content(new HttpEntityPayload(response, entity)); AttributesMap contentAttrs = fetchedContent.getAttributes(); contentAttrs.set(Content.CONTENT_LAST_MODIFIED, getDateHeader(response, HttpHeaders.LAST_MODIFIED));
/** * Attempts to cache the merged content, falling back to temporary uncached result if necessary. */ private Content cache(final MavenPath mavenPath, final TempBlob tempBlob, final String contentType) throws IOException { AttributesMap attributesMap = new AttributesMap(); maintainCacheInfo(attributesMap); mayAddETag(attributesMap, tempBlob.getHashes()); try { return doCache(mavenPath, tempBlob, contentType, attributesMap); } catch (ONeedRetryException | ORecordDuplicatedException | MissingBlobException e) { log.debug("Conflict caching merged content {} : {}", getRepository().getName(), mavenPath.getPath(), e); } catch (Exception e) { log.warn("Problem caching merged content {} : {}", getRepository().getName(), mavenPath.getPath(), e); } invalidatePath(mavenPath); // sanity: force re-merge on next request try (InputStream in = tempBlob.get()) { // load bytes in memory before tempBlob vanishes; metadata shouldn't be too large // (don't include cache-related attributes since this content has not been cached) return new Content(new BytesPayload(toByteArray(in), contentType)); } }
return new Content(new StringPayload(content, ContentTypes.APPLICATION_JSON));