List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:com.vmware.admiral.adapter.docker.service.SystemImageRetrievalManager.java
private void getResourceAgentImage(String containerImage, Consumer<byte[]> callback) { InputStream resourceAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(containerImage); if (resourceAsStream == null) { callback.accept(null); } else {/* w ww.ja v a 2 s. c o m*/ try { callback.accept(IOUtils.toByteArray(resourceAsStream)); } catch (IOException e) { callback.accept(null); } } }
From source file:uk.co.sdev.async.http.ning.ObservableClient.java
private <T> Observable<T> execute(Supplier<Request> requestSupplier, Consumer<Request> requestConsumer, ResponseMapper<T> responseMapper) { return Observable.create(subscriber -> { try {/*from ww w .j a v a2 s . com*/ Request request = requestSupplier.get(); requestConsumer.accept(request); asyncHttpClient.executeRequest(request, new AsyncCompletionHandler<T>() { @Override public T onCompleted(Response response) throws Exception { T t = responseMapper.map(response); subscriber.onNext(t); subscriber.onCompleted(); return t; } @Override public void onThrowable(Throwable t) { subscriber.onError(t); } }); } catch (Exception e) { subscriber.onError(e); } }); }
From source file:com.vmware.admiral.adapter.docker.service.SystemImageRetrievalManager.java
private void getExternalAgentImage(String resourcesPath, String containerImage, Consumer<byte[]> callback) { Path imageResourcePath = Paths.get(resourcesPath, SYSTEM_IMAGES_PATH, containerImage); File file = imageResourcePath.toFile(); if (!file.exists()) { callback.accept(null); return;//w w w.ja va2s . com } Operation operation = new Operation(); operation.setCompletion((op, ex) -> { if (op.hasBody()) { callback.accept(op.getBody(new byte[0].getClass())); } else { callback.accept(null); } }); FileUtils.readFileAndComplete(operation, file); }
From source file:fi.hsl.parkandride.itest.AbstractReportingITest.java
protected void withWorkbook(Response response, Consumer<Workbook> workbookConsumer) { try (Workbook workbook = readWorkbookFrom(response)) { workbookConsumer.accept(workbook); } catch (IOException e) { e.printStackTrace();/*from w w w .ja v a2 s. com*/ throw new AssertionFailedError(e.getMessage()); } }
From source file:org.primeframework.mvc.test.RequestResult.java
/** * Can be called to setup objects for assertions. * * @param consumer A consumer that accepts this RequestResult. * @return This.//from ww w . ja v a 2 s . c o m */ public RequestResult setup(Consumer<RequestResult> consumer) { consumer.accept(this); return this; }
From source file:org.openecomp.sdc.be.components.impl.CommonImportManager.java
protected void setProperties(Map<String, Object> toscaJson, Consumer<List<PropertyDefinition>> consumer) { consumer.accept(getProperties(toscaJson)); }
From source file:com.liferay.apio.architect.impl.jaxrs.json.reader.MultipartBodyMessageBodyReader.java
private void _storeFileItem(FileItem fileItem, Consumer<String> valueConsumer, Consumer<BinaryFile> fileConsumer) throws IOException { if (fileItem.isFormField()) { InputStream stream = fileItem.getInputStream(); valueConsumer.accept(Streams.asString(stream)); } else {/*www. j a v a 2 s . c om*/ BinaryFile binaryFile = new BinaryFile(fileItem.getInputStream(), fileItem.getSize(), fileItem.getContentType()); fileConsumer.accept(binaryFile); } }
From source file:at.ac.tuwien.qse.sepm.service.impl.SynchronizationServiceImpl.java
@Override public void subscribeQueue(Consumer<Operation> callback) { repository.addListener(new AsyncPhotoRepository.AsyncListener() { @Override/*from ww w . j a va 2 s . c om*/ public void onQueue(AsyncPhotoRepository repository, Operation operation) { LOGGER.debug("receiving queue notification with {}", operation); callback.accept(operation); } }); }
From source file:org.commonjava.indy.bind.jaxrs.util.ResponseUtils.java
private static Response formulateResponse(final ApplicationStatus status, final Throwable error, final String message, final boolean throwIt, Consumer<ResponseBuilder> builderModifier) { final String id = generateErrorId(); final String msg = formatEntity(id, error, message).toString(); Status code = Status.INTERNAL_SERVER_ERROR; if (status != null) { code = Status.fromStatusCode(status.code()); LOGGER.debug("got error code from parameter: {}", code); } else if ((error instanceof IndyWorkflowException) && ((IndyWorkflowException) error).getStatus() > 0) { final int sc = ((IndyWorkflowException) error).getStatus(); LOGGER.debug("got error code from exception: {}", sc); code = Status.fromStatusCode(sc); }//from www .j a v a 2 s . c o m LOGGER.error("Sending error response: {} {}\n{}", code.getStatusCode(), code.getReasonPhrase(), msg); ResponseBuilder builder = Response.status(code).type(MediaType.TEXT_PLAIN).entity(msg); if (builderModifier != null) { builderModifier.accept(builder); } Response response = builder.build(); if (throwIt) { throw new WebApplicationException(error, response); } return response; }
From source file:at.ac.tuwien.qse.sepm.service.impl.SynchronizationServiceImpl.java
@Override public void subscribeComplete(Consumer<Operation> callback) { repository.addListener(new AsyncPhotoRepository.AsyncListener() { @Override/*from ww w . ja v a 2 s. c o m*/ public void onComplete(AsyncPhotoRepository repository, Operation operation) { LOGGER.debug("receiving complete notification with {}", operation); callback.accept(operation); } }); }