List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:io.github.jeddict.jcode.parser.ejs.EJSUtil.java
public static void copyDynamicResource(Consumer<FileTypeStream> parserManager, String inputResource, FileObject webRoot, Function<String, String> pathResolver, ProgressHandler handler) throws IOException { InputStream inputStream = loadResource(inputResource); try (ZipInputStream zipInputStream = new ZipInputStream(inputStream)) { ZipEntry entry;/* w w w . jav a 2 s. co m*/ while ((entry = zipInputStream.getNextEntry()) != null) { if (entry.isDirectory()) { continue; } boolean skipParsing = true; String entryName = entry.getName(); if (entryName.endsWith(".ejs")) { skipParsing = false; entryName = entryName.substring(0, entryName.lastIndexOf(".")); } String targetPath = pathResolver.apply(entryName); if (targetPath == null) { continue; } handler.progress(targetPath); FileObject target = org.openide.filesystems.FileUtil.createData(webRoot, targetPath); FileLock lock = target.lock(); try (OutputStream outputStream = target.getOutputStream(lock);) { parserManager.accept(new FileTypeStream(entryName, zipInputStream, outputStream, skipParsing)); zipInputStream.closeEntry(); } finally { lock.releaseLock(); } } } catch (Throwable ex) { Exceptions.printStackTrace(ex); System.out.println("InputResource : " + inputResource); } }
From source file:com.byteatebit.nbserver.simple.udp.UdpDatagramChannelHandler.java
@Override public SelectionKey accept(INbContext nbContext, DatagramChannel datagramChannel) { IDatagramMessageHandler messageHandler = datagramMessageHandlerFactory.create(nbContext, datagramChannel); ReadDatagramTask readDatagramTask = ReadDatagramTask.Builder.builder().withNbContext(nbContext) .withDatagramChannel(datagramChannel).withBufferSize(maxDatagramReceiveSize).build(); Consumer<Exception> exceptionHandler = (e) -> { LOG.error("Message read failed. Closing datagramChannel"); IOUtils.closeQuietly(datagramChannel); };//from w w w . j av a 2 s . c om return nbContext.register(datagramChannel, SelectionKey.OP_READ, selectionKey -> readDatagramTask.readMessage(selectionKey, messageHandler::accept, exceptionHandler), (selectionKey, ops) -> exceptionHandler.accept(new TimeoutException("write timed out")), -1); }
From source file:org.eclipse.packagedrone.utils.rpm.build.PayloadRecorder.java
public Result addDirectory(final String targetPath, final Consumer<CpioArchiveEntry> customizer) throws IOException { final CpioArchiveEntry entry = new CpioArchiveEntry(targetPath); if (customizer != null) { customizer.accept(entry); }//from w ww.j av a2 s . c om this.archiveStream.putArchiveEntry(entry); this.archiveStream.closeArchiveEntry(); return new Result(4096, null); }
From source file:org.jsweet.util.ProcessUtil.java
public static void runCmd(File directory, Consumer<String> stdoutConsumer, String... cmd) { System.out.println("run command: " + StringUtils.join(cmd, " ")); String[] args;/*from w w w. j a v a2 s . co m*/ if (System.getProperty("os.name").startsWith("Windows")) { args = new String[] { "cmd", "/c" }; } else { args = new String[0]; } args = ArrayUtils.addAll(args, cmd); System.out.println("run command: '" + StringUtils.join(args, " ") + "' in directory " + directory); // logger.fine("run command: " + StringUtils.join(args, " ")); int code = -1; try { ProcessBuilder processBuilder = new ProcessBuilder(args); processBuilder.redirectErrorStream(true); if (directory != null) { processBuilder.directory(directory); } if (!StringUtils.isBlank(EXTRA_PATH)) { processBuilder.environment().put("PATH", processBuilder.environment().get("PATH") + File.pathSeparator + EXTRA_PATH); } Process process = processBuilder.start(); try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) { String line; while ((line = in.readLine()) != null) { if (stdoutConsumer != null) { stdoutConsumer.accept(line); } else { logger.info("OUT:" + line); } } } code = process.waitFor(); if (code != 0) { throw new RuntimeException( "error while exectuting: " + StringUtils.join(args, " ") + ", error code: " + code); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:io.pravega.service.server.host.stat.AutoScaleProcessorTest.java
private EventStreamWriter<ScaleEvent> createWriter(Consumer<ScaleEvent> consumer) { return new EventStreamWriter<ScaleEvent>() { @Override/*from w w w .j a v a 2s . co m*/ public AckFuture writeEvent(ScaleEvent event) { return null; } @Override public AckFuture writeEvent(String routingKey, ScaleEvent event) { consumer.accept(event); return null; } @Override public Transaction<ScaleEvent> beginTxn(long transactionTimeout, long maxExecutionTime, long scaleGracePeriod) { return null; } @Override public Transaction<ScaleEvent> getTxn(UUID transactionId) { return null; } @Override public EventWriterConfig getConfig() { return null; } @Override public void flush() { } @Override public void close() { } }; }
From source file:org.openecomp.sdc.be.components.impl.CommonImportManager.java
protected <FieldType> void setField(Map<String, Object> toscaJson, String fieldName, Consumer<FieldType> setter) { if (toscaJson.containsKey(fieldName)) { FieldType fieldValue = (FieldType) toscaJson.get(fieldName); setter.accept(fieldValue); }//from w ww. j a v a 2 s. com }
From source file:com.thoughtworks.go.server.service.CcTrayService.java
public Appendable renderCCTrayXML(String siteUrlPrefix, String userName, Appendable appendable, Consumer<String> etagConsumer) { boolean isSecurityEnabled = goConfigService.isSecurityEnabled(); List<ProjectStatus> statuses = ccTrayCache.allEntriesInOrder(); String hashCodes = statuses.stream().map(ProjectStatus::hashCode).map(Object::toString) .collect(Collectors.joining("/")); String etag = DigestUtils.sha256Hex(siteUrlPrefix + "/" + hashCodes); etagConsumer.accept(etag); try {//www . j a v a 2s . c o m appendable.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); appendable.append("\n"); appendable.append("<Projects>"); appendable.append("\n"); for (ProjectStatus status : statuses) { if (!isSecurityEnabled || status.canBeViewedBy(userName)) { String xmlRepresentation = status.xmlRepresentation().replaceAll(ProjectStatus.SITE_URL_PREFIX, siteUrlPrefix); if (!StringUtils.isBlank(xmlRepresentation)) { appendable.append(" ").append(xmlRepresentation).append("\n"); } } } appendable.append("</Projects>"); } catch (IOException e) { // ignore. `StringBuilder#append` does not throw } return appendable; }
From source file:acmi.l2.clientmod.xdat.XdatEditor.java
public void execute(Callable<Void> r, Consumer<Exception> exceptionConsumer, Runnable finallyCallback) { executor.execute(() -> {//from w w w .j a v a2 s . co m Platform.runLater(() -> working.set(true)); try { r.call(); } catch (Exception e) { if (exceptionConsumer != null) exceptionConsumer.accept(e); } finally { try { if (finallyCallback != null) finallyCallback.run(); } finally { Platform.runLater(() -> working.set(false)); } } }); }
From source file:org.kitodo.production.services.image.ImageGenerator.java
/** * If there is a supervisor, lets him take an action. Otherwise nothing * happens./*from ww w . j a va 2 s . com*/ * * @param action * what the supervisor should do */ public void letTheSupervisorDo(Consumer<EmptyTask> action) { if (Objects.nonNull(supervisor)) { action.accept(supervisor); } }