Java Stream of toStreamLine(final Scanner scanner)

Here you can find the source of toStreamLine(final Scanner scanner)

Description

to Stream Line

License

Open Source License

Declaration

public static Stream<String> toStreamLine(final Scanner scanner) 

Method Source Code


//package com.java2s;
import java.util.Iterator;

import java.util.Objects;
import java.util.Scanner;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class Main {

    public static Stream<String> toStreamLine(final Scanner scanner) {
        Objects.requireNonNull(scanner);

        final Iterator<String> iter = new Iterator<String>() {
            final Scanner s = scanner;

            @Override/*from   w ww  .j a  va  2s  . co  m*/
            public boolean hasNext() {
                return s.hasNextLine();
            }

            @Override
            public String next() {
                return s.nextLine();
            }

        };
        return StreamSupport.stream(
                Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED | Spliterator.NONNULL), false);
    }
}

Related

  1. toStream(final T source)
  2. toStream(Iterable iterable)
  3. toStream(Iterator iter, boolean parallel)
  4. toStream(Optional value)
  5. toStream(T[] array, boolean parallel)
  6. toStreamNumber(final Scanner scanner)