title: A reader for getting text lines from a zipped text file
body: <p><strong>Summary:</strong> Having the <em>byte image</em> of <code>a.zip</code> that contains <code>a.txt</code>, how can I get a clean and correct reader that returns lines of the text file?</p>
  
  <p>I do download the image of a zip file from a web service into the <code>byte[] content</code>. I would like to write a method like </p>
  
  <pre><code>private BufferedReader contentToBufferedReader(byte[] content)
  </code></pre>
  
  <p>that would return a reader that can be used like</p>
  
  <pre><code>reader = contentToBufferedReader(content);
  while ((line = reader.readLine()) != null) {
      processThe(line);
  }
  reader.close()
  </code></pre>
  
  <p>So far, I have (<strong>updated</strong>)</p>
  
  <pre><code>private BufferedReader contentToBufferedReader(byte[] content) {
  
      ByteArrayInputStream bais = new ByteArrayInputStream(content);
      ZipInputStream zipStream = new ZipInputStream(bais);
      BufferedReader reader = null;
  
      try {
          ZipEntry entry = zipStream.getNextEntry();
  
          // I need only the first (and the only) entry from the zip file.
          if (entry != null) {
              reader = new BufferedReader(new InputStreamReader(zipStream, "UTF-8"));
              System.out.println("contentToBufferedReader(): success");
          }
      }
      catch (IOException e) {
          System.out.println("contentToBufferedReader(): failed...");
          System.out.println(e.getMessage());
      }
  
      return reader;
  }
  </code></pre>
  
  <p>I am not sure how to close all of the stream object when something fails. Moreover, I am not sure how to close them if the <code>reader</code> was successfully returned, used, and closed.</p>