@Override public InputStream openInputStream() throws IOException { return payload.openInputStream(); }
private Map<String, Object> parseJson(final Payload payload) throws IOException { try (InputStream in = payload.openInputStream()) { TypeReference<Map<String, Object>> typeReference = new TypeReference<Map<String, Object>>() { }; return mapper.readValue(in, typeReference); } } }
@Override public TempBlob createTempBlob(final Payload payload, final Iterable<HashAlgorithm> hashAlgorithms) { try (InputStream inputStream = payload.openInputStream()) { return createTempBlob(inputStream, hashAlgorithms); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public InputStream openInputStream() throws IOException { final InputStream payloadStream = payload.openInputStream(); payloadStream.skip(rangeToSend.lowerEndpoint()); return limit(payloadStream, partialSize); }
/** * Parses a search response, returning the marshaled {@link NpmSearchResponse}. */ @Nullable private NpmSearchResponse parseSearchResponse(final Repository repository, final Response response) { Payload payload = response.getPayload(); if (response.getStatus().getCode() == HttpStatus.OK && payload != null) { try (InputStream in = payload.openInputStream()) { return npmSearchResponseMapper.readFromInputStream(in); } catch (IOException e) { if (log.isDebugEnabled()) { log.warn("Unable to process search response for repository {}, skipping", repository.getName(), e); } else { log.warn("Unable to process search response for repository {}, cause: {}, skipping", repository.getName(), e.getMessage()); } } } return null; } }
/** * This method MUST NOT be called from within a TX, as it dispatches a new request! It fails with * {@code java.lang.IllegalStateException}: "Transaction already in progress" otherwise! */ private NestedAttributesMap retrievePackageRoot(final NpmPackageId packageId, final Context context) throws IOException { try { Request getRequest = new Request.Builder().action(GET).path("/" + packageId.id()).build(); Response response = getRepository().facet(ViewFacet.class).dispatch(getRequest, context); if (response.getPayload() == null) { throw new IOException("Could not retrieve package " + packageId); } final InputStream packageRootIn = response.getPayload().openInputStream(); return NpmFacetUtils.parse(() -> packageRootIn); } catch (IOException e) { throw e; } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new IOException(e); } }
private Response handleSnapshotAdminRequest(Context context, String id) throws Exception { String method = context.getRequest().getAction(); Repository repository = context.getRepository(); AptSnapshotFacet snapshotFacet = repository.facet(AptSnapshotFacet.class); switch (method) { case MKCOL: { snapshotFacet.createSnapshot(id, new AllSnapshotComponentSelector()); return HttpResponses.created(); } case PUT: { try (InputStream is = context.getRequest().getPayload().openInputStream()) { ControlFile settings = new ControlFileParser().parseControlFile(is); snapshotFacet.createSnapshot(id, new FilteredSnapshotComponentSelector(settings)); } return HttpResponses.created(); } case DELETE: { snapshotFacet.deleteSnapshot(id); return HttpResponses.noContent(); } default: return HttpResponses.methodNotAllowed(method, DELETE, MKCOL, PUT); } }