Bug 567964 - Use Files.isReadable before falling back to File IO

Some environments it is more costly to do the file open/close operation
than simply calling Files.isReadable.  First try Files.isReadable for
the golden path, if that fails then fallback to the previous behavior

Change-Id: I7aaf92c4d3d1a599343034078ebb214a8da7a305
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java
index d6b653f..08de673 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java
@@ -21,6 +21,7 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.Files;
 import org.eclipse.osgi.framework.util.FilePath;
 import org.eclipse.osgi.internal.location.LocationHelper;
 import org.eclipse.osgi.internal.messages.Msg;
@@ -69,26 +70,30 @@
 	private void checkRead(File file) throws IOException {
 		if (!file.exists())
 			throw new FileNotFoundException(file.toString());
-		if (file.isFile()) {
-			// Try to open the file to ensure that this is possible: see bug 260217
-			// If access is denied, a FileNotFoundException with (access denied) message is thrown
-			// Here file.canRead() cannot be used, because on Windows it does not
-			// return correct values - bug 6203387 in Sun's bug database
-			InputStream is = new FileInputStream(file);
-			is.close();
-		} else if (file.isDirectory()) {
-			// There is no straightforward way to check if a directory
-			// has read permissions - same issues for File.canRead() as above;
-			// try to list the files in the directory
-			File[] files = file.listFiles();
-			// File.listFiles() returns null if the directory does not exist
-			// (which is not the current case, because we check that it exists and is directory),
-			// or if an IO error occurred during the listing of the files, including if the
-			// access is denied
-			if (files == null)
-				throw new FileNotFoundException(file.toString() + " (probably access denied)"); //$NON-NLS-1$
-		} else {
-			// TODO not sure if we can get here.
+		if (!Files.isReadable(file.toPath())) {
+			if (file.isFile()) {
+				// Try to open the file to ensure that this is possible: see bug 260217
+				// If access is denied, a FileNotFoundException with (access denied) message is
+				// thrown
+				// Here file.canRead() cannot be used, because on Windows it does not
+				// return correct values - bug 6203387 in Sun's bug database
+				InputStream is = new FileInputStream(file);
+				is.close();
+			} else if (file.isDirectory()) {
+				// There is no straightforward way to check if a directory
+				// has read permissions - same issues for File.canRead() as above;
+				// try to list the files in the directory
+				File[] files = file.listFiles();
+				// File.listFiles() returns null if the directory does not exist
+				// (which is not the current case, because we check that it exists and is
+				// directory),
+				// or if an IO error occurred during the listing of the files, including if the
+				// access is denied
+				if (files == null)
+					throw new FileNotFoundException(file.toString() + " (probably access denied)"); //$NON-NLS-1$
+			} else {
+				// TODO not sure if we can get here.
+			}
 		}
 	}