Skip to content

Commit edb26be

Browse files
hansonrhansonr
authored andcommitted
java.nio, java.jar
1 parent 2c1bed4 commit edb26be

File tree

227 files changed

+54561
-860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+54561
-860
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180822113443
1+
20180823081141
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180822113443
1+
20180823081141

sources/net.sf.j2s.java.core/src/java/io/BufferedReader.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
package java.io;
1919

20+
import java.util.Iterator;
21+
import java.util.NoSuchElementException;
22+
import java.util.Spliterator;
23+
import java.util.Spliterators;
24+
import java.util.stream.Stream;
25+
import java.util.stream.StreamSupport;
26+
2027
import org.apache.harmony.luni.util.Msg;
2128

2229

@@ -500,4 +507,66 @@ public long skip(long amount) throws IOException {
500507
}
501508
throw new IllegalArgumentException();
502509
}
510+
511+
/**
512+
* Returns a {@code Stream}, the elements of which are lines read from
513+
* this {@code BufferedReader}. The {@link Stream} is lazily populated,
514+
* i.e., read only occurs during the
515+
* <a href="../util/stream/package-summary.html#StreamOps">terminal
516+
* stream operation</a>.
517+
*
518+
* <p> The reader must not be operated on during the execution of the
519+
* terminal stream operation. Otherwise, the result of the terminal stream
520+
* operation is undefined.
521+
*
522+
* <p> After execution of the terminal stream operation there are no
523+
* guarantees that the reader will be at a specific position from which to
524+
* read the next character or line.
525+
*
526+
* <p> If an {@link IOException} is thrown when accessing the underlying
527+
* {@code BufferedReader}, it is wrapped in an {@link
528+
* UncheckedIOException} which will be thrown from the {@code Stream}
529+
* method that caused the read to take place. This method will return a
530+
* Stream if invoked on a BufferedReader that is closed. Any operation on
531+
* that stream that requires reading from the BufferedReader after it is
532+
* closed, will cause an UncheckedIOException to be thrown.
533+
*
534+
* @return a {@code Stream<String>} providing the lines of text
535+
* described by this {@code BufferedReader}
536+
*
537+
* @since 1.8
538+
*/
539+
public Stream<String> lines() {
540+
Iterator<String> iter = new Iterator<String>() {
541+
String nextLine = null;
542+
543+
@Override
544+
public boolean hasNext() {
545+
if (nextLine != null) {
546+
return true;
547+
} else {
548+
try {
549+
nextLine = readLine();
550+
return (nextLine != null);
551+
} catch (IOException e) {
552+
throw new UncheckedIOException(e);
553+
}
554+
}
555+
}
556+
557+
@Override
558+
public String next() {
559+
if (nextLine != null || hasNext()) {
560+
String line = nextLine;
561+
nextLine = null;
562+
return line;
563+
} else {
564+
throw new NoSuchElementException();
565+
}
566+
}
567+
};
568+
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(
569+
iter, Spliterator.ORDERED | Spliterator.NONNULL), false);
570+
}
571+
503572
}

0 commit comments

Comments
 (0)