ivolff

Scaner

Nov 6th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.*;
  4. import java.util.NoSuchElementException;
  5.  
  6. public class MyScanner {
  7.  
  8.     private BufferedReader reader;
  9.  
  10.     public MyScanner( InputStream in ){
  11.         reader = new BufferedReader( new InputStreamReader( in ) );
  12.     }
  13.  
  14.     private String curString;
  15.  
  16.     private String getCurString() throws IOException {
  17.         return reader.readLine();
  18.     }
  19.  
  20.     private boolean isNotDoubleCheck = true;
  21.  
  22.     public boolean hasNextLine() throws IOException {
  23.         if( isNotDoubleCheck ){
  24.             curString = getCurString();
  25.         }
  26.         isNotDoubleCheck = false;
  27.         return !curString.isEmpty();
  28.     }
  29.  
  30.  
  31.     public String nextLine() throws IOException {
  32.         if( hasNextLine() ){
  33.             isNotDoubleCheck = true;
  34.             return curString;
  35.         }
  36.         else{
  37.             isNotDoubleCheck = true;
  38.             throw new NoSuchElementException( "Next line not found" );
  39.         }
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment