United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-7133484 : (fs) Need FileTypeDetector implementation for MacOSX

Details
Type:
Enhancement
Submit Date:
2012-01-26
Status:
Resolved
Updated Date:
2015-06-12
Project Name:
JDK
Resolved Date:
2013-05-17
Component:
core-libs
OS:
os_x
Sub-Component:
java.nio
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
7u4
Fixed Versions:
8

Related Reports
Duplicate:

Sub Tasks

Description
From http://java.net/jira/browse/MACOSX_PORT-153 --

Files.probeContentType return null for htm/html files

Test for reproducing issue:

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class ContentTypeTest {

public static void main(String[] argv) {
String[] input = {"index.html", "index.htm"};
int failCount = 0;
try {
for (String s : input) {
Path path = Paths.get(s);
String filetype = Files.probeContentType(path);
if (filetype == null || !filetype.equals("text/html")) { System.out.println(path.toString() + " - file type is not text/html; file type is - " + filetype); failCount++; } else { System.out.println(path.toString() + " - file type is text/html"); }
}
} catch (Exception e) { e.printStackTrace(); }
if(failCount > 0) { System.out.println("TEST FAIL!"); } else { System.out.println("TEST PASS!"); }
}
}

Test result:

index.html - file type is not text/html; file type is - null
index.htm - file type is not text/html; file type is - null
TEST FAIL!

                                    

Comments
Don't be ridiculous.  What users are going to know that they need to do that, and how to do it?
That's equivalent to asking each individual user to patch this bug.  End users are not ever going to do that.

This issue was marked as fixed after one internal person patched a single machine to work.  That is the only known OS X machine that this method works on.

Note also that while it is true that the documentation says that "it returns null when the file type is not recognized", it also states that there is a default implementation, which would imply that it is possible to get something other than a null response.  On OS X null is returned always.. the default implementation does nothing useful on any typical end user's system.
                                     
2015-06-12
~/mime.types can be created by the user, there isn't a system wide MIME type tables that we are aware of OS X.
                                     
2015-06-12
~/mime.types is not present on OS X.  This bug should be re-opened and a reasonable solution should be investigated.
                                     
2015-06-12
The FileTypeDetector included on Mac uses mime types file and was added in the fix of JDK-7142921. It requires ~/.mime.types file to be present.
                                     
2013-05-17
EVALUATION

I've changed the synopsis to reflect what this issue is about. In summary, we need a FileTypeDetector for MacOSX that plugs into its file type associations. This is not critical for 7u4 as the Files.probeContentType method is very clear that it returns null when the file type is not recognized (which is the case with the test case).
                                     
2012-01-26



Hardware and Software, Engineered to Work Together