Fix b/16139028 Part1: Close DirectoryStreams to avoid leaking resources.

This change closes the DirectoryStreams in FsAdaptor, as they were
being leaked.  Also closes a Windows HANDLE in a finally clause
in WindowFileDelegate.getLastAccessTime to ensure it gets called.

Code Review:  http://codereview.appspot.com/107710043
diff --git a/src/com/google/enterprise/adaptor/fs/FsAdaptor.java b/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
index 6f549aa..5c00990 100644
--- a/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
+++ b/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
@@ -41,6 +41,7 @@
 import java.io.Writer;
 import java.nio.charset.Charset;
 import java.nio.file.AccessDeniedException;
+import java.nio.file.DirectoryStream;
 import java.nio.file.InvalidPathException;
 import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
@@ -271,7 +272,7 @@
 
     // Verify that the adaptor has permission to read the contents of the root.
     try {
-      delegate.newDirectoryStream(rootPath);
+      delegate.newDirectoryStream(rootPath).close();
     } catch (AccessDeniedException e) {
       throw new IOException("Unable to list the contents of " + rootPath +
           ". This can happen if the Windows account used to crawl " +
@@ -610,10 +611,15 @@
     if (docIsDirectory) {
       HtmlResponseWriter writer = createHtmlResponseWriter(resp);
       writer.start(id, getFileName(doc));
-      for (Path file : delegate.newDirectoryStream(doc)) {
-        if (isFileOrFolder(file)) {
-          writer.addLink(delegate.newDocId(file), getFileName(file));
+      DirectoryStream<Path> files = delegate.newDirectoryStream(doc);
+      try {
+        for (Path file : files) {
+          if (isFileOrFolder(file)) {
+            writer.addLink(delegate.newDocId(file), getFileName(file));
+          }
         }
+      } finally {
+        files.close();
       }
       writer.finish();
     } else {
diff --git a/src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java b/src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java
index 19bedfa..7ce01db 100644
--- a/src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java
+++ b/src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java
@@ -92,19 +92,21 @@
 
   @Override
   public FileTime getLastAccessTime(Path doc) throws IOException {
+    WinBase.FILETIME.ByReference accessTime =
+        new WinBase.FILETIME.ByReference();
     HANDLE handle = kernel32.CreateFile(doc.toString(), WinNT.GENERIC_READ,
         WinNT.FILE_SHARE_READ | WinNT.FILE_SHARE_WRITE,
         new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING,
         WinNT.FILE_ATTRIBUTE_NORMAL, null);
-      if (Kernel32.INVALID_HANDLE_VALUE.equals(handle)) {
-        throw new IOException("Unable to open " + doc
-            + ". GetLastError: " + kernel32.GetLastError());
-      }
-
-    WinBase.FILETIME.ByReference accessTime =
-        new WinBase.FILETIME.ByReference();
-    kernel32.GetFileTime(handle, null, accessTime, null);
-    kernel32.CloseHandle(handle);
+    if (Kernel32.INVALID_HANDLE_VALUE.equals(handle)) {
+      throw new IOException("Unable to open " + doc
+           + ". GetLastError: " + kernel32.GetLastError());
+    }
+    try {  
+      kernel32.GetFileTime(handle, null, accessTime, null);
+    } finally {
+      kernel32.CloseHandle(handle);
+    }
     return FileTime.fromMillis(accessTime.toDate().getTime());
   }