title: When using Java's FileLock, is it ok to let close() to automatically do a lock.release()?
body: <p>As most should know <code>close()</code> also closes any streams uses.</p>
  
  <p>This allows the follow code:</p>
  
  <pre><code>BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(...)));
  ...
  br.close();
  </code></pre>
  
  <p>This is nice, since we don't need a reference to <code>FileInputStream</code> and remember to close it.</p>
  
  <p>But does it also work for <code>FileLock</code>s?</p>
  
  <pre><code>final FileInputStream fis = new FileInputStream(new File("buffer.txt"));
  final FileChannel c = fis.getChannel();
  final FileLock lock = c.lock(0L, Long.MAX_VALUE, true);
  final BufferedReader br = new BufferedReader(new InputStreamReader(fis));
  
  try {
      while(br.ready()) {
          System.out.println(br.readLine());
      }
  } finally {
      br.close();
  }
  </code></pre>
  
  <p>I've tried this code and the lock is correctly released when <code>br.close()</code> is called, but is is safe to do so?  The <a href="http://java.sun.com/javase/6/docs/api/java/io/Closeable.html#close()" rel="nofollow noreferrer">Closeable JavaDoc</a> says, <em>"Closes this stream and releases any system resources associated with it."</em>  Am I safe to assume that I am using <code>close()</code> as specified to <code>release()</code> the lock?</p>