title: Do I need to call both .dispose() (javax.jcr.Binary) and .close() (java.io.InputStream)?
body: <p>Do I need to define the Binary object separately so I can call <code>.dispose();</code> on it (see <code>methodOne()</code>) or will that be handled automatically when auto-closing the InputStream (see <code>methodTwo()</code>)?</p>
  
  <pre><code>private void methodOne(Resource resource) {
      Binary binary = resource.getValueMap().get("jcr:data", Binary.class);
      try {
          InputStream is = null;
          try {
              is = binary.getStream();
              // ...do something with the InputStream...
          } catch (RepositoryException e) {
              LOG.error("RepositoryException trying to get an InputStream from the resource.");
          } finally {
              if (is != null) {
                  IOUtils.closeQuietly(is);
              }
          }
      } finally {
          binary.dispose();
      }
  }
  
  private void methodTwo(Resource resource) {
      try (InputStream is = resource.getValueMap().get("jcr:data", Binary.class).getStream()) {
          // ...do something with the InputStream...
      } catch (IOException e) {
          LOG.error("IOException from trying to auto-close InputStream.");
      } catch (RepositoryException e) {
          LOG.error("RepositoryException trying to get an InputStream from the resource.");
      }
  }
  </code></pre>
  
  <p>I'm genuinely confused on how to even test if the anonymous Binary resource in methodTwo is being disposed of properly, which is why I'm even asking this question in the first place.</p>