changeset 710:6c350c38b283

Files#probeContentType does not return null for unrecognized files (GNOME 2.0 only)
author alanb
date Tue, 14 Oct 2008 09:40:04 +0100
parents 0c74f1370dfb
children 928099dfe108
files src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java test/java/nio/file/Files/ContentType.java
diffstat 2 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java	Tue Oct 14 09:37:04 2008 +0100
+++ b/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java	Tue Oct 14 09:40:04 2008 +0100
@@ -62,16 +62,22 @@
 
         UnixPath path = (UnixPath)obj;
         NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getPathForSysCalls());
-        byte[] mimeType;
         try {
-            mimeType = (gioAvailable) ? probeUsingGio(buffer.address()) :
-                probeUsingGnomeVfs(buffer.address());
+            if (gioAvailable) {
+                byte[] type = probeUsingGio(buffer.address());
+                return (type == null) ? null : new String(type);
+            } else {
+                byte[] type = probeUsingGnomeVfs(buffer.address());
+                if (type == null)
+                    return null;
+                String s = new String(type);
+                return s.equals("application/octet-stream") ? null : s;
+            }
+
         } finally {
             buffer.release();
         }
-        if (mimeType == null)
-            return null;
-        return new String(mimeType);
+
     }
 
     // GIO
--- a/test/java/nio/file/Files/ContentType.java	Tue Oct 14 09:37:04 2008 +0100
+++ b/test/java/nio/file/Files/ContentType.java	Tue Oct 14 09:40:04 2008 +0100
@@ -42,6 +42,10 @@
         return file;
     }
 
+    static FileRef createUnknownFile() throws IOException {
+        return File.createTempFile("unknown", "unknown-file-type-789").toPath();
+    }
+
     static FileRef createGrapeFile() throws IOException {
         return File.createTempFile("red", ".grape").toPath();
     }
@@ -61,6 +65,15 @@
         } finally {
             file.delete();
         }
+        file = createUnknownFile();
+        try {
+            String type = Files.probeContentType(file);
+            if (type != null)
+                 throw new RuntimeException(file + " should not be recognized as:" +
+                     type);
+        } finally {
+            file.delete();
+        }
 
         // exercise custom file type detector
         file = createGrapeFile();