title: Reading single InputStream from multiple methods
body: <p>I have initialized an InputStream in a single method in a class and passing it to next method for processing. The InputStream essentially encapsulates CSV file for processing.</p>
  
  <p>Another method calls 2 different methods passing in same InputStream one for retrieving headers and another for processing contents. The structure looks something as given below:</p>
  
  <pre><code>main() {
    FileInputStream fis = new FileInputStream("FileName.CSV");
    BufferedInputStream bis = new BufferedInputStream(fis);
    InputStreamReader isr = new InputStreamReader(bis);
  
    processCSV(isr);
  }
  
  processCSV(Reader isr) {
    fetchHeaders(isr);
    processContentRows(isr);
  }
  
  fetchHeaders(Reader isr) {
    //Use BufferedReader to retrieve first line of CSV
    //Even tried mark() and reset() here
  }
  
  processContentRows(Reader isr) {
    //Cannot read the values, fetches null from InputStream :(
  }
  </code></pre>
  
  <p>Am I doing something wrong here? Is there any way I can reuse InputStream across different method calls.</p>
  
  <p>I am putting up complete program that can mimic the issue below:</p>
  
  <pre><code>  import java.io.FileInputStream;
    import java.io.BufferedInputStream;
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
  
    public class MarkResetTest
    {
      public static void main(String a[])
      {
          FileInputStream fis = null;
          BufferedInputStream bis = null;
          InputStreamReader isr = null;
          BufferedReader br = null;
          BufferedReader br2 = null;
  
          try {
              fis = new FileInputStream("C:/Test/Customers.csv");
              bis = new BufferedInputStream(fis);
              isr = new InputStreamReader(bis, "Unicode");    
  
              System.out.println("BR readLine()");        
  
              br = new BufferedReader(isr);
              //System.out.println(br.markSupported());
              br.mark(1000);
              System.out.println(br.readLine());
              br.reset();
              //System.out.println(br.readLine());            
  
              System.out.println("BR2 readLine()");
  
              br2 = new BufferedReader(isr);
              System.out.println(br2.readLine());
          }
          catch(Exception e) {
              System.out.println("Exception::" + e);
          }
          finally {
              try {
                  br.close();
                  isr.close();
                  bis.close();
                  fis.close();
              }
              catch(Exception e) {
                  System.out.println("Exception while closing streams :: " + e);
              }
          }
      }
    }
  </code></pre>