List of usage examples for java.util.stream Stream forEach
void forEach(Consumer<? super T> action);
From source file:nl.mpi.oai.harvester.control.FileSynchronization.java
/** * Move file of temporary directory/*from w w w . ja va 2 s .c o m*/ */ private static void move(final File file, final String dir) { Stream<String> fileStream = getAsStream(file); if (fileStream != null) { fileStream.forEach(l -> { try { FileUtils.moveFileToDirectory(FileUtils.getFile(dir + "/" + l), FileUtils.getFile(dir + "_new/"), true); } catch (IOException e) { logger.error("Error while moving " + l + " file: ", e); } }); } }
From source file:nl.mpi.oai.harvester.control.FileSynchronization.java
/** * * Removes files based on list provided in file *//*w ww . j a v a 2 s. c o m*/ private static void delete(final Provider provider, final File file, final String dir) { Stream<String> fileStream = getAsStream(file); if (fileStream != null) { fileStream.forEach(l -> { Path path = Paths.get(dir + l); if (Files.exists(path)) { try { Files.delete(path); saveToHistoryFile(provider, path, Operation.DELETE); } catch (IOException e) { logger.error("Error while deleting " + path + " file: ", e); } } }); } }
From source file:objective.taskboard.utils.ZipUtils.java
public static void unzip(Stream<ZipStreamEntry> stream, Path output) { if (output.toFile().isFile()) throw new RuntimeException("Output must be a directory"); try {//ww w . j a v a 2s . co m stream.forEach(ze -> { Path entryPath = output.resolve(ze.getName()); try { if (ze.isDirectory()) { createDirectories(entryPath); } else { createDirectories(entryPath.getParent()); copy(ze.getInputStream(), entryPath); } } catch (IOException e) { throw new UncheckedIOException(e); } }); } finally { stream.close(); } }
From source file:objective.taskboard.utils.ZipUtils.java
public static void zip(Stream<ZipStreamEntry> stream, OutputStream outputStream) { try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) { stream.forEach(ze -> { ZipEntry newEntry = new ZipEntry(ze.getName()); try { zipOutputStream.putNextEntry(newEntry); IOUtils.copy(ze.getInputStream(), zipOutputStream); } catch (IOException e) { throw new UncheckedIOException(e); }/*from www . j ava2s .co m*/ }); } catch (IOException e) { throw new UncheckedIOException(e); } finally { stream.close(); } }
From source file:org.apache.cassandra.index.SecondaryIndexManager.java
private static void executeAllBlocking(Stream<Index> indexers, Function<Index, Callable<?>> function) { if (function == null) { logger.error("failed to flush indexes: {} because flush task is missing.", indexers); return;//from www. j av a 2s . co m } List<Future<?>> waitFor = new ArrayList<>(); indexers.forEach(indexer -> { Callable<?> task = function.apply(indexer); if (null != task) waitFor.add(blockingExecutor.submit(task)); }); FBUtilities.waitOnFutures(waitFor); }
From source file:org.apache.geode.internal.DeployedJar.java
/** * Unregisters all functions from this jar if it was undeployed (i.e. newVersion == null), or all * functions not present in the new version if it was redeployed. * * @param newVersion The new version of this jar that was deployed, or null if this jar was * undeployed.// w w w.j a v a2s. c o m */ protected synchronized void cleanUp(DeployedJar newVersion) { Stream<String> oldFunctions = this.registeredFunctions.stream().map(Function::getId); Stream<String> removedFunctions; if (newVersion == null) { removedFunctions = oldFunctions; } else { Predicate<String> isRemoved = (String oldFunctionId) -> !newVersion.hasFunctionWithId(oldFunctionId); removedFunctions = oldFunctions.filter(isRemoved); } removedFunctions.forEach(FunctionService::unregisterFunction); this.registeredFunctions.clear(); try { TypeRegistry typeRegistry = ((InternalCache) CacheFactory.getAnyInstance()).getPdxRegistry(); if (typeRegistry != null) { typeRegistry.flushCache(); } } catch (CacheClosedException ignored) { // That's okay, it just means there was nothing to flush to begin with } }
From source file:org.apache.hadoop.hbase.client.AsyncBatchRpcRetryingCaller.java
private void failAll(Stream<Action> actions, int tries, Throwable error, ServerName serverName) { long currentTime = EnvironmentEdgeManager.currentTime(); String extras = getExtraContextForError(serverName); actions.forEach(action -> failOne(action, tries, error, currentTime, extras)); }
From source file:org.apache.hadoop.hbase.client.AsyncBatchRpcRetryingCaller.java
private void failAll(Stream<Action> actions, int tries) { actions.forEach(action -> { CompletableFuture<T> future = action2Future.get(action); if (future.isDone()) { return; }//from w ww.j av a 2 s. c o m future.completeExceptionally(new RetriesExhaustedException(tries, Optional.ofNullable(removeErrors(action)).orElse(Collections.emptyList()))); }); }
From source file:org.apache.james.mailbox.backup.Zipper.java
private void storeMessages(Stream<MailboxMessage> messages, ZipArchiveOutputStream archiveOutputStream) { messages.forEach(Throwing.<MailboxMessage>consumer(message -> { storeInArchive(message, archiveOutputStream); }).sneakyThrow());// www . ja va 2 s . c om }
From source file:org.beryx.viewreka.fxapp.ProjectLibs.java
public void addUncatalogedLibs() { FileChooser libChooser = new FileChooser(); libChooser.setTitle("Select libraries"); libChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("jar and vbundle files", "*.jar", "*.vbundle"), new FileChooser.ExtensionFilter("All files", "*.*")); GuiSettings guiSettings = guiSettingsManager.getSettings(); File initialDir = guiSettings.getMostRecentProjectDir(); String lastLibDirPath = guiSettings.getProperty(PROP_LAST_LIBRARY_DIR, null, true); if (lastLibDirPath != null) { try {/*w w w .jav a 2s . com*/ File dir = new File(lastLibDirPath); if (dir.isDirectory()) { initialDir = dir; } } catch (Exception e) { log.warn("Cannot retrieve last library path", e); } } libChooser.setInitialDirectory(initialDir); List<File> libFiles = libChooser.showOpenMultipleDialog(getScene().getWindow()); if (libFiles != null && !libFiles.isEmpty()) { guiSettings.setProperty(PROP_LAST_LIBRARY_DIR, libFiles.get(0).getParent()); Stream<String> libStream = libFiles.stream().map(f -> f.getAbsolutePath()) .filter(s -> (s != null && !s.isEmpty())).filter(s -> lstLib.getItems().stream() .map(entry -> entry.getCellText()).noneMatch(txt -> txt.equals(s))); libStream.forEach(s -> lstLib.getItems().add(LibListEntry.forFilePath(s))); } }