title: How does BufferedReader read files from S3?
body: <p>I have a very large file (several GB) in AWS S3, and I only need a small number of lines in the file which satisfy a certain condition. I don't want to load the entire file in-memory and then search for and print those few lines - the memory load for this would be too high. The right way would be to only load those lines in-memory which are needed.</p>
  
  <p>As per AWS documentation <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingJava.html" rel="noreferrer">to read from file</a>:</p>
  
  <pre><code>fullObject = s3Client.getObject(new GetObjectRequest(bucketName, key));
   displayTextInputStream(fullObject.getObjectContent());
  
  private static void displayTextInputStream(InputStream input) throws IOException {
      // Read the text input stream one line at a time and display each line.
      BufferedReader reader = new BufferedReader(new InputStreamReader(input));
      String line = null;
      while ((line = reader.readLine()) != null) {
          System.out.println(line);
      }
      System.out.println();
  }
  </code></pre>
  
  <p>Here we are using a <a href="https://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html" rel="noreferrer">BufferedReader</a>. It is not clear to me what is happening underneath here.</p>
  
  <p>Are we making a network call to S3 each time we are reading a new line, and only keeping the current line in the buffer? Or is the entire file loaded in-memory and then read line-by-line by BufferedReader? Or is it somewhere in between?</p>