@Override public InputStream read() throws IOException { Content content = mavenFacet.get(mavenPath); if (content != null) { return content.openInputStream(); } return null; }
private static Payload cachePayload(final Content remote) throws IOException { try (InputStream in = remote.openInputStream()) { return new BytesPayload(toByteArray(in), remote.getContentType()); } } }
private void addReadMetadata(final MavenPath mavenPath, final List<Envelope> metadatas, final Entry<Repository, Content> entry) throws IOException { final String origin = entry.getKey().getName() + " @ " + mavenPath.getPath(); try { final Metadata metadata = MavenModels.readMetadata(entry.getValue().openInputStream()); if (metadata == null) { log.debug("Corrupted repository metadata: {}, source: {}", origin, entry.getValue()); return; } metadatas.add(new Envelope(origin, metadata)); } catch (IOException e) { log.debug("Error downloading repository metadata: {}, source: {}", origin, entry.getValue()); throw new IOException("Error downloading repository metadata for " + origin + ": " + e.getMessage(), e); } }
final Closer closer = Closer.create(); try { final JsonParser jsonParser = mapper.getFactory().createParser(closer.register(fullIndex.openInputStream())); if (jsonParser.nextToken() == JsonToken.START_OBJECT && NpmMetadataUtils.META_UPDATED.equals(jsonParser.nextFieldName())) {
private void processMember(final Closer closer, final ArrayList<JsonParser> parsers, final Repository repository) throws IOException { UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier()); try { // do not pass since upstream, ask for full index to cache full index, and searchIndex() will filter it final Content index = repository.facet(NpmSearchIndexFacet.class).searchIndex(null); // managing the content stream, since JsonParser is configured to NOT close the stream, see NpmJsonUtils.mapper final JsonParser jsonParser = mapper.getFactory().createParser(closer.register(index.openInputStream())); closer.register(jsonParser); // adjust parser position, skip first field of NpmMetadataUtils.META_UPDATED as rest are all value objects if (jsonParser.nextToken() == JsonToken.START_OBJECT && NpmMetadataUtils.META_UPDATED.equals(jsonParser.nextFieldName())) { jsonParser.nextValue(); // skip value parsers.add(jsonParser); } } finally { UnitOfWork.end(); } }
/** * Reads content stored at given path as {@link Metadata}. Returns null if the content does not exist. */ @Nullable public static Metadata read(final Repository repository, final MavenPath mavenPath) throws IOException { final Content content = repository.facet(MavenFacet.class).get(mavenPath); if (content == null) { return null; } else { Metadata metadata = MavenModels.readMetadata(content.openInputStream()); if (metadata == null) { log.warn("Corrupted metadata {} @ {}", repository.getName(), mavenPath.getPath()); } return metadata; } }
final Content jarFile = mavenFacet.get(mavenPath); if (jarFile != null) { try (ZipInputStream zip = new ZipInputStream(jarFile.openInputStream())) { ZipEntry entry; while ((entry = zip.getNextEntry()) != null) {
final Content content = mavenFacet.get(checksumPath); if (content != null) { try (InputStream is = content.openInputStream()) { final String mavenChecksum = DigestExtractor.extract(is); if (Objects.equals(assetChecksum, mavenChecksum)) {
private Content putMetadata(final String path, final Content content, final AssetKind assetKind) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), HASH_ALGORITHMS)) { try (TempBlob newTempBlob = indexYamlAbsoluteUrlRewriter.removeUrlsFromIndexYamlAndWriteToTempBlob(tempBlob, getRepository()) ) { return saveMetadataAsAsset(path, newTempBlob, content, assetKind); } } }
private Content putComponent(final Content content, final String fileName, final AssetKind assetKind) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), HASH_ALGORITHMS)) { HelmAttributes helmAttributes = helmAttributeParser.getAttributesFromInputStream(tempBlob.get()); return doCreateOrSaveComponent(helmAttributes, fileName, tempBlob, content, assetKind); } }
InputStream releaseStream = null; if (itemsByRole.containsKey(SnapshotItem.Role.RELEASE_INDEX)) { releaseStream = itemsByRole.get(SnapshotItem.Role.RELEASE_INDEX).content.openInputStream(); InputStream is = itemsByRole.get(SnapshotItem.Role.RELEASE_INLINE_INDEX).content.openInputStream(); if (is != null) { ArmoredInputStream aIs = new ArmoredInputStream(is);
for (Map.Entry<Repository, Content> entry : contents.entrySet()) { String origin = entry.getKey().getName() + " @ " + mavenPath.getPath(); ArchetypeCatalog catalog = MavenModels.readArchetypeCatalog(entry.getValue().openInputStream()); if (catalog == null) { log.debug("Corrupted archetype catalog: {}", origin);
() -> { try { return content.openInputStream();
@Transactional(retryOn = { ONeedRetryException.class }) @Override public void createSnapshot(String id, SnapshotComponentSelector selector) throws IOException { StorageTx tx = UnitOfWork.currentTx(); StorageFacet storageFacet = facet(StorageFacet.class); Bucket bucket = tx.findBucket(getRepository()); Component component = tx.createComponent(bucket, getRepository().getFormat()).name(id); tx.saveComponent(component); for (SnapshotItem item : collectSnapshotItems(selector)) { String assetName = createAssetPath(id, item.specifier.path); Asset asset = tx.createAsset(bucket, component).name(assetName); try (final TempBlob streamSupplier = storageFacet.createTempBlob(item.content.openInputStream(), FacetHelper.hashAlgorithms)) { AssetBlob blob = tx.createBlob(item.specifier.path, streamSupplier, FacetHelper.hashAlgorithms, null, FacetHelper.determineContentType(item), true); tx.attachBlob(asset, blob); } finally { item.content.close(); } tx.saveAsset(asset); } }