Fix for FileNotFound exception when file is missing

Reverting the use of toRealPath back to getCanonical file and File.get().
I also changed the initialization of getDocumentContent to only call
isHidden after first confirming that the file actually excists.
diff --git a/src/com/google/enterprise/adaptor/fs/FileDelegate.java b/src/com/google/enterprise/adaptor/fs/FileDelegate.java
index 2f56901..0e65917 100644
--- a/src/com/google/enterprise/adaptor/fs/FileDelegate.java
+++ b/src/com/google/enterprise/adaptor/fs/FileDelegate.java
@@ -28,7 +28,7 @@
 interface FileDelegate {
   /**
    * Returns the real {@link Path} represented by the path string.
-   * This is equivalent to {@code Paths.get(pathname).toRealPath()}.
+   * This is equivalent to {@code Paths.get(pathname)}.
    *
    * @param pathname the path string
    * @return the real Path
diff --git a/src/com/google/enterprise/adaptor/fs/FsAdaptor.java b/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
index 03e2d48..1db3114 100644
--- a/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
+++ b/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
@@ -289,6 +289,13 @@
         new Object[] {req, resp});
     DocId id = req.getDocId();
     Path doc = delegate.getPath(id.getUniqueId());
+
+    if (!isSupportedPath(doc)) {
+      log.log(Level.WARNING, "The path {0} is not a supported file type.", doc);
+      resp.respondNotFound();
+      return;
+    }
+
     final boolean docIsDirectory = delegate.isDirectory(doc);
 
     if (!id.equals(delegate.newDocId(doc))) {
@@ -303,12 +310,6 @@
       return;
     }
 
-    if (!isSupportedPath(doc)) {
-      log.log(Level.WARNING, "The path {0} is not a supported file type.", doc);
-      resp.respondNotFound();
-      return;
-    }
-
     // Populate the document metadata.
     BasicFileAttributes attrs = delegate.readBasicAttributes(doc);
     final FileTime lastAccessTime = attrs.lastAccessTime();
diff --git a/src/com/google/enterprise/adaptor/fs/NioFileDelegate.java b/src/com/google/enterprise/adaptor/fs/NioFileDelegate.java
index 674f960..80bdbe8 100644
--- a/src/com/google/enterprise/adaptor/fs/NioFileDelegate.java
+++ b/src/com/google/enterprise/adaptor/fs/NioFileDelegate.java
@@ -16,6 +16,7 @@
 
 import com.google.enterprise.adaptor.DocId;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.attribute.AclFileAttributeView;
@@ -37,7 +38,7 @@
 
   @Override
   public Path getPath(String pathname) throws IOException {
-    return Paths.get(pathname).toRealPath(LinkOption.NOFOLLOW_LINKS);
+    return Paths.get(pathname);
   }
 
   @Override
@@ -82,9 +83,9 @@
 
   @Override
   public DocId newDocId(Path doc) throws IOException {
-    Path realPath = doc.toRealPath(LinkOption.NOFOLLOW_LINKS);
-    String id = realPath.toString();
-    if (isDirectory(realPath) && !id.endsWith("/")) {
+    File file = doc.toFile().getCanonicalFile();
+    String id = file.getAbsolutePath();
+    if (file.isDirectory() && !id.endsWith("/")) {
       id += "/";
     }
     return new DocId(id);
diff --git a/src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java b/src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java
index aacdc0a..c310616 100644
--- a/src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java
+++ b/src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java
@@ -205,9 +205,9 @@
 
   @Override
   public DocId newDocId(Path doc) throws IOException {
-    Path realPath = doc.toRealPath();
-    String id = realPath.toString().replace('\\', '/');
-    if (isDirectory(realPath) && !id.endsWith("/")) {
+    File file = doc.toFile().getCanonicalFile();
+    String id = file.getAbsolutePath().replace('\\', '/');
+    if (file.isDirectory() && !id.endsWith("/")) {
       id += "/";
     }
     if (id.startsWith("//")) {