< prev index next >

src/java.base/share/classes/java/io/BufferedReader.java

Print this page
rev 15357 : imported patch 8163517-Various-cleanup-in-java-io-code


 543      * operation is undefined.
 544      *
 545      * <p> After execution of the terminal stream operation there are no
 546      * guarantees that the reader will be at a specific position from which to
 547      * read the next character or line.
 548      *
 549      * <p> If an {@link IOException} is thrown when accessing the underlying
 550      * {@code BufferedReader}, it is wrapped in an {@link
 551      * UncheckedIOException} which will be thrown from the {@code Stream}
 552      * method that caused the read to take place. This method will return a
 553      * Stream if invoked on a BufferedReader that is closed. Any operation on
 554      * that stream that requires reading from the BufferedReader after it is
 555      * closed, will cause an UncheckedIOException to be thrown.
 556      *
 557      * @return a {@code Stream<String>} providing the lines of text
 558      *         described by this {@code BufferedReader}
 559      *
 560      * @since 1.8
 561      */
 562     public Stream<String> lines() {
 563         Iterator<String> iter = new Iterator<String>() {
 564             String nextLine = null;
 565 
 566             @Override
 567             public boolean hasNext() {
 568                 if (nextLine != null) {
 569                     return true;
 570                 } else {
 571                     try {
 572                         nextLine = readLine();
 573                         return (nextLine != null);
 574                     } catch (IOException e) {
 575                         throw new UncheckedIOException(e);
 576                     }
 577                 }
 578             }
 579 
 580             @Override
 581             public String next() {
 582                 if (nextLine != null || hasNext()) {
 583                     String line = nextLine;


 543      * operation is undefined.
 544      *
 545      * <p> After execution of the terminal stream operation there are no
 546      * guarantees that the reader will be at a specific position from which to
 547      * read the next character or line.
 548      *
 549      * <p> If an {@link IOException} is thrown when accessing the underlying
 550      * {@code BufferedReader}, it is wrapped in an {@link
 551      * UncheckedIOException} which will be thrown from the {@code Stream}
 552      * method that caused the read to take place. This method will return a
 553      * Stream if invoked on a BufferedReader that is closed. Any operation on
 554      * that stream that requires reading from the BufferedReader after it is
 555      * closed, will cause an UncheckedIOException to be thrown.
 556      *
 557      * @return a {@code Stream<String>} providing the lines of text
 558      *         described by this {@code BufferedReader}
 559      *
 560      * @since 1.8
 561      */
 562     public Stream<String> lines() {
 563         Iterator<String> iter = new Iterator<>() {
 564             String nextLine = null;
 565 
 566             @Override
 567             public boolean hasNext() {
 568                 if (nextLine != null) {
 569                     return true;
 570                 } else {
 571                     try {
 572                         nextLine = readLine();
 573                         return (nextLine != null);
 574                     } catch (IOException e) {
 575                         throw new UncheckedIOException(e);
 576                     }
 577                 }
 578             }
 579 
 580             @Override
 581             public String next() {
 582                 if (nextLine != null || hasNext()) {
 583                     String line = nextLine;
< prev index next >