@Override public IOptional<T, E> consume(final IConsumer<T, E> consumer) { try { consumer.consume(this.value); return this; } catch (final Exception exception) { return Optional.failed(this.exceptionClass, exception, null); } }
default void foreach(final IConsumer<? super T, IOException> action) throws IOException { Objects.requireNonNull(action); for (final T t : this) { action.consume(t); } } }
default <E extends Exception> void foreach(final IConsumer<? super T, E> consumer) throws E { Objects.requireNonNull(consumer); for (final T t : this) { consumer.consume(t);; } }
default void foreach(final IConsumer<? super T, IOException> action) throws IOException { Objects.requireNonNull(action); for (final T t : this) { action.consume(t); } } }
default <E extends Exception> void forEachRemaining(final IConsumer<? super T, E> consumer) throws E { Objects.requireNonNull(consumer); while (hasNext()) { consumer.consume(next()); } } }
default <E extends Exception> void otherwise(final IConsumer<String, E> consumer) throws E { if (!isValid()) { consumer.consume(getMessage()); } }
default <E extends Exception> void otherwise(final IConsumer<String, E> consumer) throws E { if (!isValid()) { consumer.consume(getMessage()); } }
default void foreach(final IConsumer<O, E> consumer) throws E { final IIterator<O, E> iterator = this.iterator(); while (iterator.hasNext()) { final O value = iterator.next(); consumer.consume(value); } }
public void launch() { try { @SuppressWarnings("hiding") final List<String> command = new ArrayList<>(); if (OperationSystemUtilities.isLinux() || OperationSystemUtilities.isBSD() || OperationSystemUtilities.isUnix()) { command.add("sh"); //$NON-NLS-1$ command.add("-c"); //$NON-NLS-1$ } else if (OperationSystemUtilities.isWindows()) { command.add("cmd"); //$NON-NLS-1$ command.add("/c"); //$NON-NLS-1$ } final String commandString = create(this.command, this.arguments); Optional.of(commandString).consum(c -> command.add(c)); final ProcessBuilder processBuilder = new ProcessBuilder(command); Optional.of(this.inputStreamConsumer).consum(consumer -> processBuilder.redirectError(Redirect.PIPE)); Optional.of(this.errorStreamConsumer).consum(consumer -> processBuilder.redirectInput(Redirect.PIPE)); final Process process = processBuilder.start(); Optional.of(this.inputStreamConsumer).consum(consumer -> consumer.consume(process.getInputStream())); Optional.of(this.errorStreamConsumer).consum(consumer -> consumer.consume(process.getErrorStream())); if (this.isWaitFor) { process.waitFor(); } } catch (final InterruptedException exception) { // nothing to do } catch (final IOException exception) { logger.log(ILevel.DEBUG, exception.getMessage(), exception); } }
final Process process = processBuilder.start(); Optional.of(IOException.class, this.inputStreamConsumer).consume( consumer -> consumer.consume(process.getInputStream())); Optional.<IConsumer<InputStream, IOException>, IOException> of(IOException.class, this.errorStreamConsumer).consume( consumer -> consumer.consume(process.getErrorStream())); if (this.isWaitFor) { final ICancelerListener listener = () -> process.destroy();