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.miovision.oss.awsbillingtools.parser.DetailedLineItemParser.java

private static List<String> readTags(Iterator<CSVRecord> iterator) {
    return iterator.hasNext()
            ? StreamSupport.stream(iterator.next().spliterator(), false).skip(20).collect(Collectors.toList())
            : new ArrayList<>(0);
}

From source file:pl.hycom.pip.messanger.service.ProductService.java

public List<Product> findAllProducts() {
    log.info("Searching all products");

    return StreamSupport.stream(productRepository.findAll().spliterator(), false).collect(Collectors.toList());
}

From source file:fi.vrk.xroad.catalog.persistence.TestUtil.java

public Optional getEntity(Iterable entities, Long l) {
    return StreamSupport.stream(entities.spliterator(), false).filter(e -> getIdentifier(e).equals(l))
            .findFirst();//from w  ww. j  av  a2 s  . c o m
}

From source file:org.n52.iceland.config.json.AbstractJsonDao.java

protected Stream<JsonNode> createStream(JsonNode node) {
    return StreamSupport.stream(node.spliterator(), false);
}

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

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

From source file:org.codice.ddf.catalog.ui.metacard.impl.ZipSplitter.java

@Override
public Stream<StorableResource> split(StorableResource storableResource,
        Map<String, ? extends Serializable> arguments) throws IOException {
    ZipIterator zipIterator = new ZipIterator(storableResource.getInputStream());
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(zipIterator, Spliterator.NONNULL), false)
            .onClose(zipIterator::close);
}

From source file:org.hawkular.rest.ResponseUtil.java

/**
 * Similar to {@link #created(UriInfo, String)} but used when more than 1 entity is created during the request.
 * <p/>/*from   www . j a  v a 2 s.c om*/
 * The provided list of ids is converted to URIs (by merely appending the ids using the
 * {@link UriBuilder#segment(String...)} method) and put in the response as its entity.
 *
 * @param info uri info to help with converting ids to URIs
 * @param ids  the list of ids of the entities
 * @return the response builder with status 201 and entity set
 */
public static Response.ResponseBuilder created(UriInfo info, Spliterator<String> ids) {
    return Response.status(CREATED).entity(
            StreamSupport.stream(ids, false).map((id) -> info.getRequestUriBuilder().segment(id).build()));
}

From source file:io.curly.bloodhound.service.ElasticQueryService.java

@HystrixCommand(fallbackMethod = "noResults")
public Observable<List<Artifact>> getResults(String query) {
    log.debug("Querying data for {}", query);
    return new ObservableResult<List<Artifact>>() {
        @Override//from  w  ww .ja  v  a 2s  .c  o m
        public List<Artifact> invoke() {
            return StreamSupport
                    .stream(repository.search(elasticQueryBuilder.build(query)).spliterator(), false)
                    .collect(Collectors.toList());
        }
    };
}

From source file:com.simiacryptus.mindseye.applications.HadoopUtil.java

/**
 * To stream stream.//from  w  ww . j  a va  2  s.c om
 *
 * @param <T>            the type parameter
 * @param remoteIterator the remote iterator
 * @return the stream
 */
@Nonnull
public static <T> Stream<T> toStream(final RemoteIterator<T> remoteIterator) {
    return StreamSupport.stream(Spliterators.spliterator(new Iterator<T>() {
        @Override
        public boolean hasNext() {
            try {
                return remoteIterator.hasNext();
            } catch (Throwable e) {
                logger.warn("Error listing files", e);
                return false;
            }
        }

        @Override
        public T next() {
            try {
                return remoteIterator.next();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }, -1, Spliterator.IMMUTABLE), true);
}

From source file:com.paolodragone.util.io.datasets.tsv.TsvDataSetReader.java

@Override
public Stream<? extends DataRecord> getRecordStream() {
    if (!isOpen()) {
        throw new IllegalStateException("This reader is not opened.");
    }/*  w  w w  . ja  v  a2 s.  c  o m*/
    return StreamSupport.stream(spliterator(), false);
}