Example usage for java.util.stream StreamSupport stream

List of usage examples for java.util.stream StreamSupport stream

Introduction

In this page you can find the example usage for java.util.stream StreamSupport stream.

Prototype

public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel) 

Source Link

Document

Creates a new sequential or parallel Stream from a Spliterator .

Usage

From source file:com.simiacryptus.util.test.EnglishWords.java

/**
 * Load stream.//from   w w w .j av  a  2s  . c o m
 *
 * @return the stream
 */
public static Stream<EnglishWords> load() {
    if (thread == null) {
        synchronized (WikiArticle.class) {
            if (thread == null) {
                thread = new Thread(EnglishWords::read);
                thread.setDaemon(true);
                thread.start();
            }
        }
    }
    Iterator<EnglishWords> iterator = new AsyncListIterator<>(queue, thread);
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), false)
            .filter(x -> x != null);
}

From source file:objective.taskboard.utils.ZipUtils.java

public static Stream<ZipStreamEntry> stream(InputStream inputStream) {
    ZipEntryIterator it = new ZipEntryIterator(new ZipInputStream(inputStream));
    return StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED | Spliterator.NONNULL), false);
}

From source file:com.simiacryptus.util.test.Shakespeare.java

/**
 * Load stream./*from   w w w . ja  va2s .co m*/
 *
 * @return the stream
 */
public static Stream<Shakespeare> load() {
    if (thread == null) {
        synchronized (WikiArticle.class) {
            if (thread == null) {
                thread = new Thread(Shakespeare::read);
                thread.setDaemon(true);
                thread.start();
            }
        }
    }
    Iterator<Shakespeare> iterator = new AsyncListIterator<>(queue, thread);
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), false)
            .filter(x -> x != null);
}

From source file:com.avanza.ymer.MongoDocumentCollection.java

@Override
public Stream<DBObject> findAll() {
    return StreamSupport.stream(dbCollection.find().spliterator(), false);
}

From source file:com.lithium.flow.shell.sshj.SshjExec.java

@Override
@Nonnull
public Stream<String> out() {
    return StreamSupport.stream(new InputStreamSpliterator(command.getInputStream(), UTF_8), false);
}

From source file:uk.trainwatch.app.util.Main.java

private static int run(String... args) throws Exception {

    // Load all of the utility implementations
    ServiceLoader<Utility> loader = ServiceLoader.load(Utility.class);
    Map<String, Utility> tools = StreamSupport.stream(loader.spliterator(), false)
            .collect(Collectors.toMap(Utility::getName, Function.identity()));

    Supplier<String> toolNames = () -> tools.keySet().stream().sorted()
            .collect(Collectors.joining(", ", "Available tools: ", ""));

    Consumer<Utility> showHelp = u -> new HelpFormatter().printHelp(u.getName(), u.getOptions());

    if (args.length == 0) {
        LOG.log(Level.INFO, toolNames);
        return 1;
    }//from  www.jav  a  2s.c o  m

    String toolName = args[0];

    if ("-?".equals(toolName) || "--help".equals(toolName)) {
        HelpFormatter hf = new HelpFormatter();
        tools.keySet().stream().sorted().map(tools::get).filter(Objects::nonNull).forEach(showHelp);
    } else {
        Utility util = getUtility(tools, toolNames, toolName);
        if (util != null) {

            String toolArgs[] = Arrays.copyOfRange(args, 1, args.length);

            if (toolArgs.length == 0 || "-?".equals(toolArgs[0]) || "--help".equals(toolArgs[0])) {
                new HelpFormatter().printHelp(util.getName(), util.getOptions());
            } else {
                try {
                    CommandLineParser parser = new BasicParser();
                    CommandLine cmd = parser.parse(util.getOptions(), toolArgs);
                    if (util.parseArgs(cmd)) {
                        // Simple banner for identifying whats being run
                        LoggingUtils.logBanner("Utility: " + util.getName());
                        try {
                            CDIUtils.inject(util);
                            util.call();
                            return 0;
                        } finally {
                            LoggingUtils.logBanner("End run of " + util.getName());
                        }
                    } else {
                        LOG.log(Level.WARNING, () -> "Failed to parse args " + cmd);
                        showHelp.accept(util);
                    }
                } catch (UnrecognizedOptionException ex) {
                    LOG.log(Level.WARNING, ex, ex::getMessage);
                    showHelp.accept(util);
                } catch (UncheckedSQLException ex) {
                    LOG.log(Level.SEVERE, null, ex.getCause());
                } catch (Exception ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    return 1;
}

From source file:com.github.steveash.guavate.Guavate.java

/**
 * Converts an iterable to a serial stream.
 * <p>// w w  w  .  jav a 2s.  co  m
 * This is harder than it should be, a method {@code Stream.of(Iterable)}
 * would have been appropriate, but cannot be added now.
 * @param <T> the type of element in the iterable
 * @param iterable the iterable to convert
 * @return a stream of the elements in the iterable
 */
public static <T> Stream<T> stream(Iterable<T> iterable) {
    return StreamSupport.stream(iterable.spliterator(), false);
}

From source file:com.vmware.photon.controller.model.adapters.vsphere.vapi.TaggingClient.java

public List<String> getAttachedTags(ManagedObjectReference ref) throws IOException, RpcException {
    RpcRequest call = newCall("com.vmware.cis.tagging.tag_association", "list_attached_tags");
    bindToSession(call, this.sessionId);

    call.params.input = newNode();//from w  w w.  j a v a2  s  .c  o  m
    call.params.input.putObject("STRUCTURE").putObject("operation-input").put("object_id", newDynamicId(ref));

    RpcResponse resp = rpc(call);
    throwIfError("Cannot get tags for object " + VimUtils.convertMoRefToString(ref), resp);

    return StreamSupport.stream(resp.result.get("output").spliterator(), false).map(JsonNode::asText)
            .collect(Collectors.toList());
}

From source file:org.jamocha.filter.SymbolCollector.java

private Stream<Pair<VariableSymbol, SingleSlotVariable>> getSlotVariableStream() {
    return this.symbols.stream().flatMap(symbol -> StreamSupport
            .stream(symbol.getEqual().getSlotVariables().spliterator(), true).map(sv -> Pair.of(symbol, sv)));
}

From source file:com.lithium.flow.shell.sshj.SshjExec.java

@Override
@Nonnull
public Stream<String> err() {
    return StreamSupport.stream(new InputStreamSpliterator(command.getErrorStream(), UTF_8), false);
}